From 48833b5c306dfc88669e4cf4fc77640c426c519b Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 3 Mar 2018 15:47:29 -0500 Subject: move technical compatibility details into TRACE log (#453) --- src/SMAPI/Framework/ModLoading/AssemblyLoader.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/SMAPI/Framework/ModLoading') diff --git a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs index ccbd053e..7dcf94bf 100644 --- a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs +++ b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs @@ -270,9 +270,10 @@ namespace StardewModdingAPI.Framework.ModLoading break; case InstructionHandleResult.NotCompatible: + this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Broken code in {filename}: {handler.NounPhrase}."); if (!assumeCompatible) throw new IncompatibleInstructionException(handler.NounPhrase, $"Found an incompatible CIL instruction ({handler.NounPhrase}) while loading assembly {filename}."); - this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Found an incompatible CIL instruction ({handler.NounPhrase}) while loading assembly {filename}, but SMAPI is configured to allow it anyway. The mod may crash or behave unexpectedly.", LogLevel.Warn); + this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Found broken code ({handler.NounPhrase}) while loading assembly {filename}, but SMAPI is configured to allow it anyway. The mod may crash or behave unexpectedly.", LogLevel.Warn); break; case InstructionHandleResult.DetectedGamePatch: -- cgit From adebec4dd4d3bf4b45f23377a6ab1525fa2d78ef Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 3 Mar 2018 17:49:24 -0500 Subject: automatically detect broken code (#453) --- src/SMAPI/Framework/ModLoading/AssemblyLoader.cs | 5 +- .../Finders/ReferenceToMissingMemberFinder.cs | 87 ++++++++++++++ .../ReferenceToMemberWithUnexpectedTypeFinder.cs | 131 +++++++++++++++++++++ src/SMAPI/Metadata/InstructionMetadata.cs | 48 ++++---- src/SMAPI/StardewModdingAPI.csproj | 2 + 5 files changed, 250 insertions(+), 23 deletions(-) create mode 100644 src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs create mode 100644 src/SMAPI/Framework/ModLoading/Rewriters/ReferenceToMemberWithUnexpectedTypeFinder.cs (limited to 'src/SMAPI/Framework/ModLoading') diff --git a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs index 7dcf94bf..f0e186a1 100644 --- a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs +++ b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs @@ -238,10 +238,13 @@ namespace StardewModdingAPI.Framework.ModLoading // check CIL instructions ILProcessor cil = method.Body.GetILProcessor(); - foreach (Instruction instruction in cil.Body.Instructions.ToArray()) + var instructions = cil.Body.Instructions; + // ReSharper disable once ForCanBeConvertedToForeach -- deliberate access by index so each handler sees replacements from previous handlers + for (int offset = 0; offset < instructions.Count; offset++) { foreach (IInstructionHandler handler in handlers) { + Instruction instruction = instructions[offset]; InstructionHandleResult result = handler.Handle(module, cil, instruction, this.AssemblyMap, platformChanged); this.ProcessInstructionHandleResult(mod, handler, result, loggedMessages, logPrefix, assumeCompatible, filename); if (result == InstructionHandleResult.Rewritten) diff --git a/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs new file mode 100644 index 00000000..60373c9d --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs @@ -0,0 +1,87 @@ +using System.Linq; +using Mono.Cecil; +using Mono.Cecil.Cil; + +namespace StardewModdingAPI.Framework.ModLoading.Finders +{ + /// Finds references to a field, property, or method which no longer exists. + /// This implementation is purely heuristic. It should never return a false positive, but won't detect all cases. + internal class ReferenceToMissingMemberFinder : IInstructionHandler + { + /********* + ** Accessors + *********/ + /// A brief noun phrase indicating what the instruction finder matches. + public string NounPhrase { get; private set; } = ""; + + + /********* + ** Public methods + *********/ + /// Perform the predefined logic for a method if applicable. + /// The assembly module containing the instruction. + /// The method definition containing the instruction. + /// Metadata for mapping assemblies to the current platform. + /// Whether the mod was compiled on a different platform. + public virtual InstructionHandleResult Handle(ModuleDefinition module, MethodDefinition method, PlatformAssemblyMap assemblyMap, bool platformChanged) + { + return InstructionHandleResult.None; + } + + /// Perform the predefined logic for an instruction if applicable. + /// The assembly module containing the instruction. + /// The CIL processor. + /// The instruction to handle. + /// Metadata for mapping assemblies to the current platform. + /// Whether the mod was compiled on a different platform. + public virtual InstructionHandleResult Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, PlatformAssemblyMap assemblyMap, bool platformChanged) + { + // field reference + FieldReference fieldRef = RewriteHelper.AsFieldReference(instruction); + if (fieldRef != null) + { + FieldDefinition target = fieldRef.DeclaringType.Resolve()?.Fields.FirstOrDefault(p => p.Name == fieldRef.Name); + if (target == null) + { + this.NounPhrase = $"reference to {fieldRef.DeclaringType.FullName}.{fieldRef.Name} (no such field)"; + return InstructionHandleResult.NotCompatible; + } + } + + // method reference + MethodReference methodRef = RewriteHelper.AsMethodReference(instruction); + if (methodRef != null && !this.IsUnsupported(methodRef)) + { + MethodDefinition target = methodRef.DeclaringType.Resolve()?.Methods.FirstOrDefault(p => p.Name == methodRef.Name); + if (target == null) + { + this.NounPhrase = this.IsProperty(methodRef) + ? $"reference to {methodRef.DeclaringType.FullName}.{methodRef.Name.Substring(4)} (no such property)" + : $"reference to {methodRef.DeclaringType.FullName}.{methodRef.Name} (no such method)"; + return InstructionHandleResult.NotCompatible; + } + } + + return InstructionHandleResult.None; + } + + + /********* + ** Private methods + *********/ + /// Get whether a method reference is a special case that's not currently supported (e.g. array methods). + /// The method reference. + private bool IsUnsupported(MethodReference method) + { + return + method.DeclaringType.Name.Contains("["); // array methods + } + + /// Get whether a method reference is a property getter or setter. + /// The method reference. + private bool IsProperty(MethodReference method) + { + return method.Name.StartsWith("get_") || method.Name.StartsWith("set_"); + } + } +} diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/ReferenceToMemberWithUnexpectedTypeFinder.cs b/src/SMAPI/Framework/ModLoading/Rewriters/ReferenceToMemberWithUnexpectedTypeFinder.cs new file mode 100644 index 00000000..f2080e40 --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/Rewriters/ReferenceToMemberWithUnexpectedTypeFinder.cs @@ -0,0 +1,131 @@ +using System.Linq; +using System.Text.RegularExpressions; +using Mono.Cecil; +using Mono.Cecil.Cil; + +namespace StardewModdingAPI.Framework.ModLoading.Rewriters +{ + /// Finds references to a field, property, or method which returns a different type than the code expects. + /// This implementation is purely heuristic. It should never return a false positive, but won't detect all cases. + internal class ReferenceToMemberWithUnexpectedTypeFinder : IInstructionHandler + { + /********* + ** Properties + *********/ + /// A pattern matching type name substrings to strip for display. + private readonly Regex StripTypeNamePattern = new Regex(@"`\d+(?=<)", RegexOptions.Compiled); + + + /********* + ** Accessors + *********/ + /// A brief noun phrase indicating what the instruction finder matches. + public string NounPhrase { get; private set; } = ""; + + + /********* + ** Public methods + *********/ + /// Perform the predefined logic for a method if applicable. + /// The assembly module containing the instruction. + /// The method definition containing the instruction. + /// Metadata for mapping assemblies to the current platform. + /// Whether the mod was compiled on a different platform. + public virtual InstructionHandleResult Handle(ModuleDefinition module, MethodDefinition method, PlatformAssemblyMap assemblyMap, bool platformChanged) + { + return InstructionHandleResult.None; + } + + /// Perform the predefined logic for an instruction if applicable. + /// The assembly module containing the instruction. + /// The CIL processor. + /// The instruction to handle. + /// Metadata for mapping assemblies to the current platform. + /// Whether the mod was compiled on a different platform. + public virtual InstructionHandleResult Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, PlatformAssemblyMap assemblyMap, bool platformChanged) + { + // field reference + FieldReference fieldRef = RewriteHelper.AsFieldReference(instruction); + if (fieldRef != null) + { + // get target field + FieldDefinition targetField = fieldRef.DeclaringType.Resolve()?.Fields.FirstOrDefault(p => p.Name == fieldRef.Name); + if (targetField == null) + return InstructionHandleResult.None; + + // validate return type + string actualReturnTypeID = this.GetComparableTypeID(targetField.FieldType); + string expectedReturnTypeID = this.GetComparableTypeID(fieldRef.FieldType); + if (actualReturnTypeID != expectedReturnTypeID) + { + this.NounPhrase = $"reference to {fieldRef.DeclaringType.FullName}.{fieldRef.Name} (field returns {this.GetFriendlyTypeName(targetField.FieldType, actualReturnTypeID)}, not {this.GetFriendlyTypeName(fieldRef.FieldType, expectedReturnTypeID)})"; + return InstructionHandleResult.NotCompatible; + } + } + + // method reference + MethodReference methodReference = RewriteHelper.AsMethodReference(instruction); + if (methodReference != null) + { + // get potential targets + MethodDefinition[] candidateMethods = methodReference.DeclaringType.Resolve()?.Methods.Where(found => found.Name == methodReference.Name).ToArray(); + if (candidateMethods == null || !candidateMethods.Any()) + return InstructionHandleResult.None; + + // compare return types + MethodDefinition methodDef = methodReference.Resolve(); + if (methodDef == null) + { + this.NounPhrase = $"reference to {methodReference.DeclaringType.FullName}.{methodReference.Name} (no such method)"; + return InstructionHandleResult.NotCompatible; + } + + string expectedReturnType = this.GetComparableTypeID(methodDef.ReturnType); + if (candidateMethods.All(method => this.GetComparableTypeID(method.ReturnType) != expectedReturnType)) + { + this.NounPhrase = $"reference to {methodDef.DeclaringType.FullName}.{methodDef.Name} (no such method returns {this.GetFriendlyTypeName(methodDef.ReturnType, expectedReturnType)})"; + return InstructionHandleResult.NotCompatible; + } + } + + return InstructionHandleResult.None; + } + + + /********* + ** Private methods + *********/ + /// Get a unique string representation of a type. + /// The type reference. + private string GetComparableTypeID(TypeReference type) + { + return this.StripTypeNamePattern.Replace(type.FullName, ""); + } + + /// Get a shorter type name for display. + /// The type reference. + /// The comparable type ID from . + private string GetFriendlyTypeName(TypeReference type, string typeID) + { + // most common built-in types + switch (type.FullName) + { + case "System.Boolean": + return "bool"; + case "System.Int32": + return "int"; + case "System.String": + return "string"; + } + + // most common unambiguous namespaces + foreach (string @namespace in new[] { "Microsoft.Xna.Framework", "Netcode", "System", "System.Collections.Generic" }) + { + if (type.Namespace == @namespace) + return typeID.Substring(@namespace.Length + 1); + } + + return typeID; + } + } +} diff --git a/src/SMAPI/Metadata/InstructionMetadata.cs b/src/SMAPI/Metadata/InstructionMetadata.cs index 5bb461c1..9e2b7967 100644 --- a/src/SMAPI/Metadata/InstructionMetadata.cs +++ b/src/SMAPI/Metadata/InstructionMetadata.cs @@ -21,7 +21,27 @@ namespace StardewModdingAPI.Metadata return new IInstructionHandler[] { /**** - ** throw exception for incompatible code + ** rewrite CIL to fix incompatible code + ****/ + // crossplatform + new MethodParentRewriter(typeof(SpriteBatch), typeof(SpriteBatchMethods), onlyIfPlatformChanged: true), + + // Stardew Valley 1.2 + new FieldToPropertyRewriter(typeof(Game1), nameof(Game1.activeClickableMenu)), + new FieldToPropertyRewriter(typeof(Game1), nameof(Game1.currentMinigame)), + new FieldToPropertyRewriter(typeof(Game1), nameof(Game1.gameMode)), + new FieldToPropertyRewriter(typeof(Game1), nameof(Game1.player)), + new FieldReplaceRewriter(typeof(Game1), "borderFont", nameof(Game1.smallFont)), + new FieldReplaceRewriter(typeof(Game1), "smoothFont", nameof(Game1.smallFont)), + + // SMAPI 1.9 + new TypeReferenceRewriter("StardewModdingAPI.Inheritance.ItemStackChange", typeof(ItemStackChange)), + + // SMAPI 2.0 + new VirtualEntryCallRemover(), // Mod.Entry changed from virtual to abstract in SMAPI 2.0, which breaks the few mods which called base.Entry() + + /**** + ** detect incompatible code ****/ // changes in Stardew Valley 1.2 (with no rewriters) new FieldFinder("StardewValley.Item", "set_Name", InstructionHandleResult.NotCompatible), @@ -66,6 +86,10 @@ namespace StardewModdingAPI.Metadata new PropertyFinder("StardewModdingAPI.Mod", "PerSaveConfigFolder", InstructionHandleResult.NotCompatible), new PropertyFinder("StardewModdingAPI.Mod", "PerSaveConfigPath", InstructionHandleResult.NotCompatible), + // broken code + new ReferenceToMissingMemberFinder(), + new ReferenceToMemberWithUnexpectedTypeFinder(), + /**** ** detect code which may impact game stability ****/ @@ -74,27 +98,7 @@ namespace StardewModdingAPI.Metadata 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), - - /**** - ** rewrite CIL to fix incompatible code - ****/ - // crossplatform - new MethodParentRewriter(typeof(SpriteBatch), typeof(SpriteBatchMethods), onlyIfPlatformChanged: true), - - // Stardew Valley 1.2 - new FieldToPropertyRewriter(typeof(Game1), nameof(Game1.activeClickableMenu)), - new FieldToPropertyRewriter(typeof(Game1), nameof(Game1.currentMinigame)), - new FieldToPropertyRewriter(typeof(Game1), nameof(Game1.gameMode)), - new FieldToPropertyRewriter(typeof(Game1), nameof(Game1.player)), - new FieldReplaceRewriter(typeof(Game1), "borderFont", nameof(Game1.smallFont)), - new FieldReplaceRewriter(typeof(Game1), "smoothFont", nameof(Game1.smallFont)), - - // SMAPI 1.9 - new TypeReferenceRewriter("StardewModdingAPI.Inheritance.ItemStackChange", typeof(ItemStackChange)), - - // SMAPI 2.0 - new VirtualEntryCallRemover() // Mod.Entry changed from virtual to abstract in SMAPI 2.0, which breaks the few mods which called base.Entry() + new EventFinder(typeof(SpecialisedEvents).FullName, nameof(SpecialisedEvents.UnvalidatedUpdateTick), InstructionHandleResult.DetectedUnvalidatedUpdateTick) }; } } diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj index 8ef3022f..a04208e4 100644 --- a/src/SMAPI/StardewModdingAPI.csproj +++ b/src/SMAPI/StardewModdingAPI.csproj @@ -103,6 +103,7 @@ + @@ -112,6 +113,7 @@ + -- cgit From f9dc901994c1a8b17e22de3f68ceb038965e0cc5 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 3 Mar 2018 22:03:41 -0500 Subject: fix error in new incompatibility finders when they resolve members in a dependency (#453) --- .../ModLoading/AssemblyDefinitionResolver.cs | 2 +- src/SMAPI/Framework/ModLoading/AssemblyLoader.cs | 24 ++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) (limited to 'src/SMAPI/Framework/ModLoading') diff --git a/src/SMAPI/Framework/ModLoading/AssemblyDefinitionResolver.cs b/src/SMAPI/Framework/ModLoading/AssemblyDefinitionResolver.cs index 4378798c..d85a9a28 100644 --- a/src/SMAPI/Framework/ModLoading/AssemblyDefinitionResolver.cs +++ b/src/SMAPI/Framework/ModLoading/AssemblyDefinitionResolver.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using Mono.Cecil; namespace StardewModdingAPI.Framework.ModLoading diff --git a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs index f0e186a1..a60f63da 100644 --- a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs +++ b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs @@ -16,17 +16,20 @@ namespace StardewModdingAPI.Framework.ModLoading /********* ** Properties *********/ + /// Encapsulates monitoring and logging. + private readonly IMonitor Monitor; + + /// Whether to enable developer mode logging. + private readonly bool IsDeveloperMode; + /// Metadata for mapping assemblies to the current platform. private readonly PlatformAssemblyMap AssemblyMap; /// A type => assembly lookup for types which should be rewritten. private readonly IDictionary TypeAssemblies; - /// Encapsulates monitoring and logging. - private readonly IMonitor Monitor; - - /// Whether to enable developer mode logging. - private readonly bool IsDeveloperMode; + /// A minimal assembly definition resolver which resolves references to known loaded assemblies. + private readonly AssemblyDefinitionResolver AssemblyDefinitionResolver; /********* @@ -41,6 +44,7 @@ namespace StardewModdingAPI.Framework.ModLoading this.Monitor = monitor; this.IsDeveloperMode = isDeveloperMode; this.AssemblyMap = Constants.GetAssemblyMap(targetPlatform); + this.AssemblyDefinitionResolver = new AssemblyDefinitionResolver(); // generate type => assembly lookup for types which should be rewritten this.TypeAssemblies = new Dictionary(); @@ -69,9 +73,8 @@ namespace StardewModdingAPI.Framework.ModLoading // get referenced local assemblies AssemblyParseResult[] assemblies; { - AssemblyDefinitionResolver resolver = new AssemblyDefinitionResolver(); HashSet visitedAssemblyNames = new HashSet(AppDomain.CurrentDomain.GetAssemblies().Select(p => p.GetName().Name)); // don't try loading assemblies that are already loaded - assemblies = this.GetReferencedLocalAssemblies(new FileInfo(assemblyPath), visitedAssemblyNames, resolver).ToArray(); + assemblies = this.GetReferencedLocalAssemblies(new FileInfo(assemblyPath), visitedAssemblyNames, this.AssemblyDefinitionResolver).ToArray(); } // validate load @@ -94,7 +97,10 @@ namespace StardewModdingAPI.Framework.ModLoading if (assembly.Status == AssemblyLoadStatus.AlreadyLoaded) continue; + // rewrite assembly bool changed = this.RewriteAssembly(mod, assembly.Definition, assumeCompatible, loggedMessages, logPrefix: " "); + + // load assembly if (changed) { if (!oneAssembly) @@ -112,6 +118,9 @@ namespace StardewModdingAPI.Framework.ModLoading this.Monitor.Log($" Loading {assembly.File.Name}...", LogLevel.Trace); lastAssembly = Assembly.UnsafeLoadFrom(assembly.File.FullName); } + + // track loaded assembly for definition resolution + this.AssemblyDefinitionResolver.Add(assembly.Definition); } // last assembly loaded is the root @@ -166,7 +175,6 @@ namespace StardewModdingAPI.Framework.ModLoading yield return new AssemblyParseResult(file, null, AssemblyLoadStatus.AlreadyLoaded); yield break; } - visitedAssemblyNames.Add(assembly.Name.Name); // yield referenced assemblies -- cgit From 19570f43129dbd3dbfa77a9c62e135a72528a68e Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 4 Mar 2018 01:07:55 -0500 Subject: simplify and always include default update URL, shorten no-longer-compatible skip messages --- docs/release-notes.md | 1 + src/SMAPI.Web/Startup.cs | 3 +- src/SMAPI/Framework/ModLoading/ModResolver.cs | 5 +- src/SMAPI/Program.cs | 5 +- src/SMAPI/StardewModdingAPI.config.json | 201 +++++++++----------------- 5 files changed, 77 insertions(+), 138 deletions(-) (limited to 'src/SMAPI/Framework/ModLoading') diff --git a/docs/release-notes.md b/docs/release-notes.md index d20584af..fb056e79 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -2,6 +2,7 @@ ## 2.5.3 * For players: * Fixed some incompatible-mod errors not showing the mod URL. + * Simplified default mod update URL, which is now always included for incompatible mods. * Updated compatibility list. * For the [log parser][]: diff --git a/src/SMAPI.Web/Startup.cs b/src/SMAPI.Web/Startup.cs index bc3e9f7b..93135239 100644 --- a/src/SMAPI.Web/Startup.cs +++ b/src/SMAPI.Web/Startup.cs @@ -147,7 +147,8 @@ namespace StardewModdingAPI.Web )); // shortcut redirects - redirects.Add(new RedirectToUrlRule("^/docs$", "https://stardewvalleywiki.com/Modding:Index")); + redirects.Add(new RedirectToUrlRule(@"^/compat\.?$", "https://stardewvalleywiki.com/Modding:SMAPI_compatibility")); + redirects.Add(new RedirectToUrlRule(@"^/docs\.?$", "https://stardewvalleywiki.com/Modding:Index")); // redirect legacy canimod.com URLs var wikiRedirects = new Dictionary diff --git a/src/SMAPI/Framework/ModLoading/ModResolver.cs b/src/SMAPI/Framework/ModLoading/ModResolver.cs index ba6dab1a..f878a1b9 100644 --- a/src/SMAPI/Framework/ModLoading/ModResolver.cs +++ b/src/SMAPI/Framework/ModLoading/ModResolver.cs @@ -98,7 +98,7 @@ namespace StardewModdingAPI.Framework.ModLoading case ModStatus.AssumeBroken: { // get reason - string reasonPhrase = mod.DataRecord.StatusReasonPhrase ?? "it's no longer compatible"; + string reasonPhrase = mod.DataRecord.StatusReasonPhrase ?? "it's outdated"; // get update URLs List updateUrls = new List(); @@ -111,6 +111,9 @@ namespace StardewModdingAPI.Framework.ModLoading if (mod.DataRecord.AlternativeUrl != null) updateUrls.Add(mod.DataRecord.AlternativeUrl); + // default update URL + updateUrls.Add("https://smapi.io/compat"); + // build error string error = $"{reasonPhrase}. Please check for a "; if (mod.DataRecord.StatusUpperVersion == null || mod.Manifest.Version.Equals(mod.DataRecord.StatusUpperVersion)) diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs index 22bceafd..979f6328 100644 --- a/src/SMAPI/Program.cs +++ b/src/SMAPI/Program.cs @@ -747,8 +747,9 @@ namespace StardewModdingAPI } catch (IncompatibleInstructionException) // details already in trace logs { - string url = modDatabase.GetModPageUrlFor(metadata.Manifest.UniqueID); - TrackSkip(metadata, $"it's no longer compatible. Please check for a newer version of the mod{(url != null ? $" at {url}" : "")}."); + string[] updateUrls = new[] { modDatabase.GetModPageUrlFor(metadata.Manifest.UniqueID), "https://smapi.io/compat" }.Where(p => p != null).ToArray(); + + TrackSkip(metadata, $"it's outdated. Please check for a new version at {string.Join(" or ", updateUrls)}."); continue; } catch (SAssemblyLoadFailedException ex) diff --git a/src/SMAPI/StardewModdingAPI.config.json b/src/SMAPI/StardewModdingAPI.config.json index 101b9dac..437feea5 100644 --- a/src/SMAPI/StardewModdingAPI.config.json +++ b/src/SMAPI/StardewModdingAPI.config.json @@ -97,15 +97,13 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "ID": "AccessChestAnywhere", "MapLocalVersions": { "1.1-1078": "1.1" }, "Default | UpdateKey": "Nexus:257", - "~1.1 | Status": "AssumeBroken", - "~1.1 | AlternativeUrl": "https://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.1 | Status": "AssumeBroken" }, "AdjustArtisanPrices": { "ID": "1e36d4ca-c7ef-4dfb-9927-d27a6c3c8bdc", "Default | UpdateKey": "Chucklefish:3532", - "~0.1 | Status": "AssumeBroken", - "~0.1 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~0.1 | Status": "AssumeBroken" }, "Adjust Monster": { @@ -127,8 +125,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "AgingMod": { "ID": "skn.AgingMod", "Default | UpdateKey": "Nexus:1129", - "~1.0 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.0 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "All Crops All Seasons": { @@ -173,8 +170,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "A Tapper's Dream": { "ID": "ddde5195-8f85-4061-90cc-0d4fd5459358", "Default | UpdateKey": "Nexus:260", - "~1.4 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.4 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.4 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Auto Animal Doors": { @@ -247,16 +243,14 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "ID": "Kithio:BetterShippingBox", "MapLocalVersions": { "1.0.1": "1.0.2" }, "Default | UpdateKey": "Chucklefish:4302", - "~1.0.2 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.0.2 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0.2 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Better Sprinklers": { "ID": "Speeder.BetterSprinklers", "FormerIDs": "SPDSprinklersMod", // changed in 2.3 "Default | UpdateKey": "Nexus:41", - "~2.3.1-pathoschild-update | Status": "AssumeBroken", // broke in SDV 1.2 - "~2.3.1-pathoschild-update | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~2.3.1-pathoschild-update | Status": "AssumeBroken" // broke in SDV 1.2 }, "Billboard Anywhere": { @@ -269,8 +263,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "ID": "KathrynHazuka.BirthdayMail", "FormerIDs": "005e02dc-d900-425c-9c68-1ff55c5a295d", // changed in 1.2.3-pathoschild-update "Default | UpdateKey": "Nexus:276", - "~1.2.2 | Status": "AssumeBroken", // broke in SDV 1.2 - "~1.2.2 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.2.2 | Status": "AssumeBroken" // broke in SDV 1.2 }, "Breed Like Rabbits": { @@ -331,8 +324,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "ID": "Speeder.ChestLabel", "FormerIDs": "SPDChestLabel", // changed in 1.5.1-pathoschild-update "Default | UpdateKey": "Nexus:242", - "~1.6 | Status": "AssumeBroken", // broke in SDV 1.1 - "~1.6 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.6 | Status": "AssumeBroken" // broke in SDV 1.1 }, "Chest Pooling": { @@ -352,8 +344,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Choose Baby Gender": { "FormerIDs": "{EntryDll: 'ChooseBabyGender.dll'}", "Default | UpdateKey": "Nexus:590", - "~1.0.2 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.0.2 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0.2 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "CJB Automation": { @@ -398,8 +389,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Cold Weather Haley": { "ID": "LordXamon.ColdWeatherHaleyPRO", "Default | UpdateKey": "Nexus:1169", - "~1.0 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.0 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Colored Chests": { @@ -411,8 +401,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Combat with Farm Implements": { "ID": "SPDFarmingImplementsInCombat", "Default | UpdateKey": "Nexus:313", - "~1.0 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.0 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Community Bundle Item Tooltip": { @@ -434,8 +423,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Configurable Shipping Dates": { "ID": "ConfigurableShippingDates", "Default | UpdateKey": "Nexus:675", - "~1.1.1 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.1.1 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.1.1 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Cooking Skill": { @@ -515,8 +503,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Customizable Traveling Cart Days": { "ID": "TravelingCartYyeahdude", "Default | UpdateKey": "Nexus:567", - "~1.0 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.0 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Custom Linens": { @@ -566,8 +553,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Dynamic Checklist": { "ID": "gunnargolf.DynamicChecklist", "Default | UpdateKey": "Nexus:1145", // added in 1.0.1-pathoschild-update - "~1.0 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.0 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Dynamic Horses": { @@ -580,8 +566,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "ID": "DynamicMachines", "MapLocalVersions": { "1.1": "1.1.1" }, "Default | UpdateKey": "Nexus:374", - "~1.1.1 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.1.1 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.1.1 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Dynamic NPC Sprites": { @@ -597,16 +582,14 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Empty Hands": { "ID": "QuicksilverFox.EmptyHands", "Default | UpdateKey": "Nexus:1176", // added in 1.0.1-pathoschild-update - "~1.0 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.0 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Enemy Health Bars": { "ID": "Speeder.HealthBars", "FormerIDs": "SPDHealthBar", // changed in 1.7.1-pathoschild-update "Default | UpdateKey": "Nexus:193", - "~1.7 | Status": "AssumeBroken", // broke in SDV 1.2 - "~1.7 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.7 | Status": "AssumeBroken" // broke in SDV 1.2 }, "Entoarox Framework": { @@ -636,15 +619,13 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "ID": "Crystalmir.ExtendedFridge", "FormerIDs": "Mystra007ExtendedFridge", // changed in 1.0.1 "Default | UpdateKey": "Nexus:485", - "~1.0 | Status": "AssumeBroken", // broke in SDV 1.2 - "~1.0 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0 | Status": "AssumeBroken" // broke in SDV 1.2 }, "Extended Greenhouse": { "ID": "ExtendedGreenhouse", "Default | UpdateKey": "Chucklefish:4303", - "~1.0.2 | Status": "AssumeBroken", // broke in SDV 1.2 - "~1.0.2 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0.2 | Status": "AssumeBroken" // broke in SDV 1.2 }, "Extended Minecart": { @@ -667,35 +648,30 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Farm Automation: Barn Door Automation": { "FormerIDs": "{EntryDll: 'FarmAutomation.BarnDoorAutomation.dll'}", - "~1.0 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.0 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Farm Automation: Item Collector": { "FormerIDs": "{EntryDll: 'FarmAutomation.ItemCollector.dll'}", - "~1.0 | Status": "AssumeBroken", // broke in SDV 1.2 - "~1.0 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0 | Status": "AssumeBroken" // broke in SDV 1.2 }, "Farm Automation Unofficial: Item Collector": { "ID": "Maddy99.FarmAutomation.ItemCollector", - "~0.5 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~0.5 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~0.5 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Farm Expansion": { "ID": "Advize.FarmExpansion", "FormerIDs": "3888bdfd-73f6-4776-8bb7-8ad45aea1915 | AdvizeFarmExpansionMod-2-0 | AdvizeFarmExpansionMod-2-0-5", // changed in 2.0, 2.0.5, and 3.0 "Default | UpdateKey": "Nexus:130", - "~2.0.5 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~2.0.5 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~2.0.5 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Farm Resource Generator": { "FormerIDs": "{EntryDll: 'FarmResourceGenerator.dll'}", "Default | UpdateKey": "Nexus:647", - "~1.0.4 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.0.4 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0.4 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Fast Animations": { @@ -718,8 +694,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "ID": "KathrynHazuka.FasterRun", "FormerIDs": "{EntryDll: 'FasterRun.dll'}", // changed in 1.1.1-pathoschild-update "Default | UpdateKey": "Nexus:733", // added in 1.1.1-pathoschild-update - "~1.1 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.1 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.1 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Fishing Adjust": { @@ -741,8 +716,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "FormerIDs": "{EntryDll: 'FlorenceMod.dll'}", "MapLocalVersions": { "1.0.1": "1.1" }, "Default | UpdateKey": "Nexus:591", - "~1.1 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.1 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.1 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Flower Color Picker": { @@ -753,8 +727,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Forage at the Farm": { "ID": "ForageAtTheFarm", "Default | UpdateKey": "Nexus:673", - "~1.5.1 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.5.1 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.5.1 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Furniture Anywhere": { @@ -812,8 +785,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Happy Animals": { "ID": "HappyAnimals", - "~1.0.3 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.0.3 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0.3 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Happy Birthday (Omegasis)": { @@ -841,8 +813,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Harvest With Scythe": { "ID": "965169fd-e1ed-47d0-9f12-b104535fb4bc", "Default | UpdateKey": "Nexus:236", - "~1.0.6 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.0.6 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0.6 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Horse Whistle (icepuente)": { @@ -858,8 +829,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Hunger for Food (Tigerle)": { "ID": "HungerForFoodByTigerle", "Default | UpdateKey": "Nexus:810", - "~0.1.2 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~0.1.2 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~0.1.2 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Hunger Mod (skn)": { @@ -882,8 +852,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Instant Geode": { "ID": "InstantGeode", - "~1.12 | Status": "AssumeBroken", // broke in SDV 1.2 - "~1.12 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.12 | Status": "AssumeBroken" // broke in SDV 1.2 }, "Instant Grow Trees": { @@ -895,8 +864,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Interaction Helper": { "ID": "HammurabiInteractionHelper", "Default | UpdateKey": "Chucklefish:4640", // added in 1.0.4-pathoschild-update - "~1.0.3 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.0.3 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0.3 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Item Auto Stacker": { @@ -926,8 +894,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "ID": "BALANCEMOD_AntiExhaustion", "MapLocalVersions": { "0.0": "1.1" }, "Default | UpdateKey": "Nexus:637", - "~1.1 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.1 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.1 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Level Extender": { @@ -1005,8 +972,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Message Box [API]? (ChatMod)": { "ID": "Kithio:ChatMod", "Default | UpdateKey": "Chucklefish:4296", - "~1.0 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.0 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Mining at the Farm": { @@ -1040,8 +1006,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "More Artifact Spots": { "ID": "451", "Default | UpdateKey": "Nexus:451", - "~1.0.1 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.0.1 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0.1 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "More Map Layers": { @@ -1070,8 +1035,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "ID": "FileLoading", "MapLocalVersions": { "1.1": "1.12" }, "Default | UpdateKey": "Nexus:1094", - "~1.12 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.12 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.12 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Museum Rearranger": { @@ -1089,8 +1053,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "New Machines": { "ID": "F70D4FAB-0AB2-4B78-9F1B-AF2CA2236A59", "Default | UpdateKey": "Chucklefish:3683", - "~4.2.1343 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~4.2.1343 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~4.2.1343 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Night Owl": { @@ -1131,8 +1094,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "No Soil Decay": { "ID": "289dee03-5f38-4d8e-8ffc-e440198e8610", "Default | UpdateKey": "Nexus:237", - "~0.5 | Status": "AssumeBroken", // broke in SDV 1.2 and uses Assembly.GetExecutingAssembly().Location - "~0.5 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~0.5 | Status": "AssumeBroken" // broke in SDV 1.2 and uses Assembly.GetExecutingAssembly().Location }, "No Soil Decay Redux": { @@ -1150,8 +1112,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "NPC Speak": { "FormerIDs": "{EntryDll: 'NpcEcho.dll'}", "Default | UpdateKey": "Nexus:694", - "~1.0 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.0 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Object Time Left": { @@ -1188,8 +1149,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "PelicanTTS": { "ID": "Platonymous.PelicanTTS", "Default | UpdateKey": "Nexus:1079", // added in 1.6.1 - "~1.6 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.6 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.6 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Persia the Mermaid - Standalone Custom NPC": { @@ -1205,8 +1165,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Persival's BundleMod": { "FormerIDs": "{EntryDll: 'BundleMod.dll'}", "Default | UpdateKey": "Nexus:438", - "~1.0 | Status": "AssumeBroken", // broke in SDV 1.1 - "~1.0 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0 | Status": "AssumeBroken" // broke in SDV 1.1 }, "Plant on Grass": { @@ -1240,8 +1199,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "ID": "Mucchan.PrairieKingMadeEasy", "FormerIDs": "{EntryDll: 'PrairieKingMadeEasy.dll'}", // changed in 1.0.1 "Default | UpdateKey": "Chucklefish:3594", - "~1.0 | Status": "AssumeBroken", // broke in SDV 1.2 - "~1.0 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0 | Status": "AssumeBroken" // broke in SDV 1.2 }, "Quest Delay": { @@ -1251,8 +1209,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Rain Randomizer": { "FormerIDs": "{EntryDll: 'RainRandomizer.dll'}", - "~1.0.3 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.0.3 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0.3 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Recatch Legendary Fish": { @@ -1274,16 +1231,14 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "RelationshipsEnhanced": { "ID": "relationshipsenhanced", "Default | UpdateKey": "Chucklefish:4435", - "~1.0 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.0 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Relationship Status": { "ID": "relationshipstatus", "MapRemoteVersions": { "1.0.5": "1.0.4" }, // not updated in manifest "Default | UpdateKey": "Nexus:751", - "~1.0.5 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.0.5 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0.5 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Rented Tools": { @@ -1312,8 +1267,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Reusable Wallpapers and Floors (Wallpaper Retain)": { "ID": "dae1b553-2e39-43e7-8400-c7c5c836134b", "Default | UpdateKey": "Nexus:356", - "~1.5 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.5 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.5 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Ring of Fire": { @@ -1395,16 +1349,14 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Shed Notifications (BuildingsNotifications)": { "ID": "TheCroak.BuildingsNotifications", "Default | UpdateKey": "Nexus:620", - "~0.4.1 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~0.4.1 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~0.4.1 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Shenandoah Project": { "ID": "Shenandoah Project", "MapRemoteVersions": { "1.1.1": "1.1" }, // not updated in manifest "Default | UpdateKey": "Nexus:756", - "~1.1.1 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.1.1 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.1.1 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Ship Anywhere": { @@ -1415,8 +1367,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Shipment Tracker": { "ID": "7e474181-e1a0-40f9-9c11-d08a3dcefaf3", "Default | UpdateKey": "Nexus:321", - "~1.1 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.1 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.1 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Shop Expander": { @@ -1430,8 +1381,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "ID": "Igorious.Showcase", "MapLocalVersions": { "0.9-500": "0.9" }, "Default | UpdateKey": "Chucklefish:4487", - "~0.9 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~0.9 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~0.9 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Shroom Spotter": { @@ -1461,8 +1411,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "ID": "6266959802", "MapLocalVersions": { "0.0": "1.4" }, "Default | UpdateKey": "Nexus:366", - "~1.2.2 | Status": "AssumeBroken", // broke in SMAPI 1.9 (has multiple Mod instances) - "~1.2.2 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.2.2 | Status": "AssumeBroken" // broke in SMAPI 1.9 (has multiple Mod instances) }, "Skill Prestige": { @@ -1506,14 +1455,12 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "ID": "Speeder.SlowerFenceDecay", "FormerIDs": "SPDSlowFenceDecay", // changed in 0.5.2-pathoschild-update "Default | UpdateKey": "Nexus:252", - "~0.5.1 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~0.5.1 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~0.5.1 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Smart Mod": { "ID": "KuroBear.SmartMod", - "~2.2 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~2.2 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~2.2 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Solar Eclipse Event": { @@ -1542,15 +1489,13 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Sprinkles": { "ID": "Platonymous.Sprinkles", "Default | UpdateKey": "Chucklefish:4592", - "~1.1.3 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.1.3 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.1.3 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Sprint and Dash": { "ID": "SPDSprintAndDash", "Default | UpdateKey": "Chucklefish:3531", - "~1.0 | Status": "AssumeBroken", // broke in SDV 1.2 - "~1.0 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0 | Status": "AssumeBroken" // broke in SDV 1.2 }, "Sprint and Dash Redux": { @@ -1563,8 +1508,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "ID": "a10d3097-b073-4185-98ba-76b586cba00c", "MapLocalVersions": { "1.0": "2.1" }, // not updated in manifest "Default | UpdateKey": "GitHub:oliverpl/SprintingMod", - "~2.1 | Status": "AssumeBroken", // broke in SDV 1.2 - "~2.1 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~2.1 | Status": "AssumeBroken" // broke in SDV 1.2 }, "StackSplitX": { @@ -1576,8 +1520,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "StaminaRegen": { "FormerIDs": "{EntryDll: 'StaminaRegen.dll'}", - "~1.0.3 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.0.3 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0.3 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Stardew Config Menu": { @@ -1599,8 +1542,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Stardew Notification": { "ID": "stardewnotification", "Default | UpdateKey": "GitHub:monopandora/StardewNotification", - "~1.7 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.7 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.7 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Stardew Symphony": { @@ -1625,8 +1567,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "StashItemsToChest": { "ID": "BlueMod_StashItemsToChest", "Default | UpdateKey": "GitHub:lambui/StardewValleyMod_StashItemsToChest", - "~1.0.1 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.0.1 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0.1 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Stephan's Lots of Crops": { @@ -1650,8 +1591,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Super Greenhouse Warp Modifier": { "ID": "SuperGreenhouse", "Default | UpdateKey": "Chucklefish:4334", - "~1.0 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.0 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Swim Almost Anywhere / Swim Suit": { @@ -1661,8 +1601,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Tainted Cellar": { "FormerIDs": "{EntryDll: 'TaintedCellar.dll'}", - "~1.0 | Status": "AssumeBroken", // broke in SDV 1.1 or 1.11 - "~1.0 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0 | Status": "AssumeBroken" // broke in SDV 1.1 or 1.11 }, "Tapper Ready": { @@ -1678,8 +1617,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Teleporter": { "ID": "Teleporter", "Default | UpdateKey": "Chucklefish:4374", - "~1.0.2 | Status": "AssumeBroken", // broke in SDV 1.2 - "~1.0.2 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0.2 | Status": "AssumeBroken" // broke in SDV 1.2 }, "The Long Night": { @@ -1738,8 +1676,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "ID": "Demiacle.UiModSuite", "MapLocalVersions": { "0.5": "1.0" }, // not updated in manifest "Default | UpdateKey": "Nexus:1023", - "~1.0 | Status": "AssumeBroken", // broke in SDV 1.2 - "~1.0 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0 | Status": "AssumeBroken" // broke in SDV 1.2 }, "Variable Grass": { @@ -1754,15 +1691,13 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "WakeUp": { "FormerIDs": "{EntryDll: 'WakeUp.dll'}", - "~1.0.2 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.0.2 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0.2 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "Wallpaper Fix": { "FormerIDs": "{EntryDll: 'WallpaperFix.dll'}", "Default | UpdateKey": "Chucklefish:4211", - "~1.1 | Status": "AssumeBroken", // broke in SMAPI 2.0 - "~1.1 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.1 | Status": "AssumeBroken" // broke in SMAPI 2.0 }, "WarpAnimals": { @@ -1772,8 +1707,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Weather Controller": { "FormerIDs": "{EntryDll: 'WeatherController.dll'}", - "~1.0.2 | Status": "AssumeBroken", // broke in SDV 1.2 - "~1.0.2 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0.2 | Status": "AssumeBroken" // broke in SDV 1.2 }, "What Farm Cave / WhatAMush": { @@ -1788,8 +1722,7 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "Wonderful Farm Life": { "FormerIDs": "{EntryDll: 'WonderfulFarmLife.dll'}", - "~1.0 | Status": "AssumeBroken", // broke in SDV 1.1 or 1.11 - "~1.0 | AlternativeUrl": "http://stardewvalleywiki.com/Modding:SMAPI_2.0" + "~1.0 | Status": "AssumeBroken" // broke in SDV 1.1 or 1.11 }, "XmlSerializerRetool": { -- cgit From 9a9622702ab310261ebedd5e0310f5f40f6812a1 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 4 Mar 2018 02:17:44 -0500 Subject: fix misplaced file (#453) --- .../ReferenceToMemberWithUnexpectedTypeFinder.cs | 131 +++++++++++++++++++++ .../ReferenceToMemberWithUnexpectedTypeFinder.cs | 131 --------------------- src/SMAPI/StardewModdingAPI.csproj | 2 +- 3 files changed, 132 insertions(+), 132 deletions(-) create mode 100644 src/SMAPI/Framework/ModLoading/Finders/ReferenceToMemberWithUnexpectedTypeFinder.cs delete mode 100644 src/SMAPI/Framework/ModLoading/Rewriters/ReferenceToMemberWithUnexpectedTypeFinder.cs (limited to 'src/SMAPI/Framework/ModLoading') diff --git a/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMemberWithUnexpectedTypeFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMemberWithUnexpectedTypeFinder.cs new file mode 100644 index 00000000..2aee7af4 --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMemberWithUnexpectedTypeFinder.cs @@ -0,0 +1,131 @@ +using System.Linq; +using System.Text.RegularExpressions; +using Mono.Cecil; +using Mono.Cecil.Cil; + +namespace StardewModdingAPI.Framework.ModLoading.Finders +{ + /// Finds references to a field, property, or method which returns a different type than the code expects. + /// This implementation is purely heuristic. It should never return a false positive, but won't detect all cases. + internal class ReferenceToMemberWithUnexpectedTypeFinder : IInstructionHandler + { + /********* + ** Properties + *********/ + /// A pattern matching type name substrings to strip for display. + private readonly Regex StripTypeNamePattern = new Regex(@"`\d+(?=<)", RegexOptions.Compiled); + + + /********* + ** Accessors + *********/ + /// A brief noun phrase indicating what the instruction finder matches. + public string NounPhrase { get; private set; } = ""; + + + /********* + ** Public methods + *********/ + /// Perform the predefined logic for a method if applicable. + /// The assembly module containing the instruction. + /// The method definition containing the instruction. + /// Metadata for mapping assemblies to the current platform. + /// Whether the mod was compiled on a different platform. + public virtual InstructionHandleResult Handle(ModuleDefinition module, MethodDefinition method, PlatformAssemblyMap assemblyMap, bool platformChanged) + { + return InstructionHandleResult.None; + } + + /// Perform the predefined logic for an instruction if applicable. + /// The assembly module containing the instruction. + /// The CIL processor. + /// The instruction to handle. + /// Metadata for mapping assemblies to the current platform. + /// Whether the mod was compiled on a different platform. + public virtual InstructionHandleResult Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, PlatformAssemblyMap assemblyMap, bool platformChanged) + { + // field reference + FieldReference fieldRef = RewriteHelper.AsFieldReference(instruction); + if (fieldRef != null) + { + // get target field + FieldDefinition targetField = fieldRef.DeclaringType.Resolve()?.Fields.FirstOrDefault(p => p.Name == fieldRef.Name); + if (targetField == null) + return InstructionHandleResult.None; + + // validate return type + string actualReturnTypeID = this.GetComparableTypeID(targetField.FieldType); + string expectedReturnTypeID = this.GetComparableTypeID(fieldRef.FieldType); + if (actualReturnTypeID != expectedReturnTypeID) + { + this.NounPhrase = $"reference to {fieldRef.DeclaringType.FullName}.{fieldRef.Name} (field returns {this.GetFriendlyTypeName(targetField.FieldType, actualReturnTypeID)}, not {this.GetFriendlyTypeName(fieldRef.FieldType, expectedReturnTypeID)})"; + return InstructionHandleResult.NotCompatible; + } + } + + // method reference + MethodReference methodReference = RewriteHelper.AsMethodReference(instruction); + if (methodReference != null) + { + // get potential targets + MethodDefinition[] candidateMethods = methodReference.DeclaringType.Resolve()?.Methods.Where(found => found.Name == methodReference.Name).ToArray(); + if (candidateMethods == null || !candidateMethods.Any()) + return InstructionHandleResult.None; + + // compare return types + MethodDefinition methodDef = methodReference.Resolve(); + if (methodDef == null) + { + this.NounPhrase = $"reference to {methodReference.DeclaringType.FullName}.{methodReference.Name} (no such method)"; + return InstructionHandleResult.NotCompatible; + } + + string expectedReturnType = this.GetComparableTypeID(methodDef.ReturnType); + if (candidateMethods.All(method => this.GetComparableTypeID(method.ReturnType) != expectedReturnType)) + { + this.NounPhrase = $"reference to {methodDef.DeclaringType.FullName}.{methodDef.Name} (no such method returns {this.GetFriendlyTypeName(methodDef.ReturnType, expectedReturnType)})"; + return InstructionHandleResult.NotCompatible; + } + } + + return InstructionHandleResult.None; + } + + + /********* + ** Private methods + *********/ + /// Get a unique string representation of a type. + /// The type reference. + private string GetComparableTypeID(TypeReference type) + { + return this.StripTypeNamePattern.Replace(type.FullName, ""); + } + + /// Get a shorter type name for display. + /// The type reference. + /// The comparable type ID from . + private string GetFriendlyTypeName(TypeReference type, string typeID) + { + // most common built-in types + switch (type.FullName) + { + case "System.Boolean": + return "bool"; + case "System.Int32": + return "int"; + case "System.String": + return "string"; + } + + // most common unambiguous namespaces + foreach (string @namespace in new[] { "Microsoft.Xna.Framework", "Netcode", "System", "System.Collections.Generic" }) + { + if (type.Namespace == @namespace) + return typeID.Substring(@namespace.Length + 1); + } + + return typeID; + } + } +} diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/ReferenceToMemberWithUnexpectedTypeFinder.cs b/src/SMAPI/Framework/ModLoading/Rewriters/ReferenceToMemberWithUnexpectedTypeFinder.cs deleted file mode 100644 index f2080e40..00000000 --- a/src/SMAPI/Framework/ModLoading/Rewriters/ReferenceToMemberWithUnexpectedTypeFinder.cs +++ /dev/null @@ -1,131 +0,0 @@ -using System.Linq; -using System.Text.RegularExpressions; -using Mono.Cecil; -using Mono.Cecil.Cil; - -namespace StardewModdingAPI.Framework.ModLoading.Rewriters -{ - /// Finds references to a field, property, or method which returns a different type than the code expects. - /// This implementation is purely heuristic. It should never return a false positive, but won't detect all cases. - internal class ReferenceToMemberWithUnexpectedTypeFinder : IInstructionHandler - { - /********* - ** Properties - *********/ - /// A pattern matching type name substrings to strip for display. - private readonly Regex StripTypeNamePattern = new Regex(@"`\d+(?=<)", RegexOptions.Compiled); - - - /********* - ** Accessors - *********/ - /// A brief noun phrase indicating what the instruction finder matches. - public string NounPhrase { get; private set; } = ""; - - - /********* - ** Public methods - *********/ - /// Perform the predefined logic for a method if applicable. - /// The assembly module containing the instruction. - /// The method definition containing the instruction. - /// Metadata for mapping assemblies to the current platform. - /// Whether the mod was compiled on a different platform. - public virtual InstructionHandleResult Handle(ModuleDefinition module, MethodDefinition method, PlatformAssemblyMap assemblyMap, bool platformChanged) - { - return InstructionHandleResult.None; - } - - /// Perform the predefined logic for an instruction if applicable. - /// The assembly module containing the instruction. - /// The CIL processor. - /// The instruction to handle. - /// Metadata for mapping assemblies to the current platform. - /// Whether the mod was compiled on a different platform. - public virtual InstructionHandleResult Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, PlatformAssemblyMap assemblyMap, bool platformChanged) - { - // field reference - FieldReference fieldRef = RewriteHelper.AsFieldReference(instruction); - if (fieldRef != null) - { - // get target field - FieldDefinition targetField = fieldRef.DeclaringType.Resolve()?.Fields.FirstOrDefault(p => p.Name == fieldRef.Name); - if (targetField == null) - return InstructionHandleResult.None; - - // validate return type - string actualReturnTypeID = this.GetComparableTypeID(targetField.FieldType); - string expectedReturnTypeID = this.GetComparableTypeID(fieldRef.FieldType); - if (actualReturnTypeID != expectedReturnTypeID) - { - this.NounPhrase = $"reference to {fieldRef.DeclaringType.FullName}.{fieldRef.Name} (field returns {this.GetFriendlyTypeName(targetField.FieldType, actualReturnTypeID)}, not {this.GetFriendlyTypeName(fieldRef.FieldType, expectedReturnTypeID)})"; - return InstructionHandleResult.NotCompatible; - } - } - - // method reference - MethodReference methodReference = RewriteHelper.AsMethodReference(instruction); - if (methodReference != null) - { - // get potential targets - MethodDefinition[] candidateMethods = methodReference.DeclaringType.Resolve()?.Methods.Where(found => found.Name == methodReference.Name).ToArray(); - if (candidateMethods == null || !candidateMethods.Any()) - return InstructionHandleResult.None; - - // compare return types - MethodDefinition methodDef = methodReference.Resolve(); - if (methodDef == null) - { - this.NounPhrase = $"reference to {methodReference.DeclaringType.FullName}.{methodReference.Name} (no such method)"; - return InstructionHandleResult.NotCompatible; - } - - string expectedReturnType = this.GetComparableTypeID(methodDef.ReturnType); - if (candidateMethods.All(method => this.GetComparableTypeID(method.ReturnType) != expectedReturnType)) - { - this.NounPhrase = $"reference to {methodDef.DeclaringType.FullName}.{methodDef.Name} (no such method returns {this.GetFriendlyTypeName(methodDef.ReturnType, expectedReturnType)})"; - return InstructionHandleResult.NotCompatible; - } - } - - return InstructionHandleResult.None; - } - - - /********* - ** Private methods - *********/ - /// Get a unique string representation of a type. - /// The type reference. - private string GetComparableTypeID(TypeReference type) - { - return this.StripTypeNamePattern.Replace(type.FullName, ""); - } - - /// Get a shorter type name for display. - /// The type reference. - /// The comparable type ID from . - private string GetFriendlyTypeName(TypeReference type, string typeID) - { - // most common built-in types - switch (type.FullName) - { - case "System.Boolean": - return "bool"; - case "System.Int32": - return "int"; - case "System.String": - return "string"; - } - - // most common unambiguous namespaces - foreach (string @namespace in new[] { "Microsoft.Xna.Framework", "Netcode", "System", "System.Collections.Generic" }) - { - if (type.Namespace == @namespace) - return typeID.Substring(@namespace.Length + 1); - } - - return typeID; - } - } -} diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj index a04208e4..42bcb9a8 100644 --- a/src/SMAPI/StardewModdingAPI.csproj +++ b/src/SMAPI/StardewModdingAPI.csproj @@ -113,7 +113,7 @@ - + -- cgit From d0b66b13bd828f81048074f442653f5467b9b18f Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 4 Mar 2018 02:25:37 -0500 Subject: fix false broken-code detection when referencing a generic type (#453) --- .../Finders/ReferenceToMemberWithUnexpectedTypeFinder.cs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/SMAPI/Framework/ModLoading') diff --git a/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMemberWithUnexpectedTypeFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMemberWithUnexpectedTypeFinder.cs index 2aee7af4..0e7344a8 100644 --- a/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMemberWithUnexpectedTypeFinder.cs +++ b/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMemberWithUnexpectedTypeFinder.cs @@ -48,6 +48,10 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders FieldReference fieldRef = RewriteHelper.AsFieldReference(instruction); if (fieldRef != null) { + // can't compare generic type parameters between definition and reference + if (fieldRef.FieldType.IsGenericInstance || fieldRef.FieldType.IsGenericParameter) + return InstructionHandleResult.None; + // get target field FieldDefinition targetField = fieldRef.DeclaringType.Resolve()?.Fields.FirstOrDefault(p => p.Name == fieldRef.Name); if (targetField == null) @@ -67,6 +71,10 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders MethodReference methodReference = RewriteHelper.AsMethodReference(instruction); if (methodReference != null) { + // can't compare generic type parameters between definition and reference + if (methodReference.ReturnType.IsGenericInstance || methodReference.ReturnType.IsGenericParameter) + return InstructionHandleResult.None; + // get potential targets MethodDefinition[] candidateMethods = methodReference.DeclaringType.Resolve()?.Methods.Where(found => found.Name == methodReference.Name).ToArray(); if (candidateMethods == null || !candidateMethods.Any()) -- cgit From 8689fe65642d07fa6a2513aa36c1389479e50d0c Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 5 Mar 2018 19:07:22 -0500 Subject: fix compatibility heuristics incorrectly flagging mods with missing optional references (#453) --- .../ReferenceToMemberWithUnexpectedTypeFinder.cs | 22 ++++++++++++++++-- .../Finders/ReferenceToMissingMemberFinder.cs | 26 ++++++++++++++++++++-- src/SMAPI/Metadata/InstructionMetadata.cs | 12 ++++++++-- 3 files changed, 54 insertions(+), 6 deletions(-) (limited to 'src/SMAPI/Framework/ModLoading') diff --git a/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMemberWithUnexpectedTypeFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMemberWithUnexpectedTypeFinder.cs index 0e7344a8..b5e45742 100644 --- a/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMemberWithUnexpectedTypeFinder.cs +++ b/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMemberWithUnexpectedTypeFinder.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Mono.Cecil; @@ -12,6 +13,9 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders /********* ** Properties *********/ + /// The assembly names to which to heuristically detect broken references. + private readonly HashSet ValidateReferencesToAssemblies; + /// A pattern matching type name substrings to strip for display. private readonly Regex StripTypeNamePattern = new Regex(@"`\d+(?=<)", RegexOptions.Compiled); @@ -26,6 +30,13 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders /********* ** Public methods *********/ + /// Construct an instance. + /// The assembly names to which to heuristically detect broken references. + public ReferenceToMemberWithUnexpectedTypeFinder(string[] validateReferencesToAssemblies) + { + this.ValidateReferencesToAssemblies = new HashSet(validateReferencesToAssemblies); + } + /// Perform the predefined logic for a method if applicable. /// The assembly module containing the instruction. /// The method definition containing the instruction. @@ -46,7 +57,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders { // field reference FieldReference fieldRef = RewriteHelper.AsFieldReference(instruction); - if (fieldRef != null) + if (fieldRef != null && this.ShouldValidate(fieldRef.DeclaringType)) { // can't compare generic type parameters between definition and reference if (fieldRef.FieldType.IsGenericInstance || fieldRef.FieldType.IsGenericParameter) @@ -69,7 +80,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders // method reference MethodReference methodReference = RewriteHelper.AsMethodReference(instruction); - if (methodReference != null) + if (methodReference != null && this.ShouldValidate(methodReference.DeclaringType)) { // can't compare generic type parameters between definition and reference if (methodReference.ReturnType.IsGenericInstance || methodReference.ReturnType.IsGenericParameter) @@ -103,6 +114,13 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders /********* ** Private methods *********/ + /// Whether references to the given type should be validated. + /// The type reference. + private bool ShouldValidate(TypeReference type) + { + return type != null && this.ValidateReferencesToAssemblies.Contains(type.Scope.Name); + } + /// Get a unique string representation of a type. /// The type reference. private string GetComparableTypeID(TypeReference type) diff --git a/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs index 60373c9d..f5e33313 100644 --- a/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs +++ b/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Linq; using Mono.Cecil; using Mono.Cecil.Cil; @@ -8,6 +9,13 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders /// This implementation is purely heuristic. It should never return a false positive, but won't detect all cases. internal class ReferenceToMissingMemberFinder : IInstructionHandler { + /********* + ** Properties + *********/ + /// The assembly names to which to heuristically detect broken references. + private readonly HashSet ValidateReferencesToAssemblies; + + /********* ** Accessors *********/ @@ -18,6 +26,13 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders /********* ** Public methods *********/ + /// Construct an instance. + /// The assembly names to which to heuristically detect broken references. + public ReferenceToMissingMemberFinder(string[] validateReferencesToAssemblies) + { + this.ValidateReferencesToAssemblies = new HashSet(validateReferencesToAssemblies); + } + /// Perform the predefined logic for a method if applicable. /// The assembly module containing the instruction. /// The method definition containing the instruction. @@ -38,7 +53,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders { // field reference FieldReference fieldRef = RewriteHelper.AsFieldReference(instruction); - if (fieldRef != null) + if (fieldRef != null && this.ShouldValidate(fieldRef.DeclaringType)) { FieldDefinition target = fieldRef.DeclaringType.Resolve()?.Fields.FirstOrDefault(p => p.Name == fieldRef.Name); if (target == null) @@ -50,7 +65,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders // method reference MethodReference methodRef = RewriteHelper.AsMethodReference(instruction); - if (methodRef != null && !this.IsUnsupported(methodRef)) + if (methodRef != null && this.ShouldValidate(methodRef.DeclaringType) && !this.IsUnsupported(methodRef)) { MethodDefinition target = methodRef.DeclaringType.Resolve()?.Methods.FirstOrDefault(p => p.Name == methodRef.Name); if (target == null) @@ -69,6 +84,13 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders /********* ** Private methods *********/ + /// Whether references to the given type should be validated. + /// The type reference. + private bool ShouldValidate(TypeReference type) + { + return type != null && this.ValidateReferencesToAssemblies.Contains(type.Scope.Name); + } + /// Get whether a method reference is a special case that's not currently supported (e.g. array methods). /// The method reference. private bool IsUnsupported(MethodReference method) diff --git a/src/SMAPI/Metadata/InstructionMetadata.cs b/src/SMAPI/Metadata/InstructionMetadata.cs index 9e2b7967..4ed1e38e 100644 --- a/src/SMAPI/Metadata/InstructionMetadata.cs +++ b/src/SMAPI/Metadata/InstructionMetadata.cs @@ -12,6 +12,14 @@ namespace StardewModdingAPI.Metadata /// Provides CIL instruction handlers which rewrite mods for compatibility and throw exceptions for incompatible code. internal class InstructionMetadata { + /********* + ** Properties + *********/ + /// The assembly names to which to heuristically detect broken references. + /// The current implementation only works correctly with assemblies that should always be present. + private readonly string[] ValidateReferencesToAssemblies = { "StardewModdingAPI", "Stardew Valley", "StardewValley" }; + + /********* ** Public methods *********/ @@ -87,8 +95,8 @@ namespace StardewModdingAPI.Metadata new PropertyFinder("StardewModdingAPI.Mod", "PerSaveConfigPath", InstructionHandleResult.NotCompatible), // broken code - new ReferenceToMissingMemberFinder(), - new ReferenceToMemberWithUnexpectedTypeFinder(), + new ReferenceToMissingMemberFinder(this.ValidateReferencesToAssemblies), + new ReferenceToMemberWithUnexpectedTypeFinder(this.ValidateReferencesToAssemblies), /**** ** detect code which may impact game stability -- cgit From b8f17e6afb00b78ac31df98f7dc3bbe071a99e47 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 11 Mar 2018 19:10:08 -0400 Subject: update rewriters for Stardew Valley 1.3 (#453) --- .../Rewriters/FieldToPropertyRewriter.cs | 18 +++++-- .../Rewriters/StaticFieldToConstantRewriter.cs | 63 ++++++++++++++++++++++ src/SMAPI/Metadata/InstructionMetadata.cs | 37 +++++++++---- src/SMAPI/StardewModdingAPI.csproj | 1 + 4 files changed, 105 insertions(+), 14 deletions(-) create mode 100644 src/SMAPI/Framework/ModLoading/Rewriters/StaticFieldToConstantRewriter.cs (limited to 'src/SMAPI/Framework/ModLoading') diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs b/src/SMAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs index a20b8bee..b1fa377a 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs @@ -14,8 +14,8 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters /// The type whose field to which references should be rewritten. private readonly Type Type; - /// The field name to rewrite. - private readonly string FieldName; + /// The property name. + private readonly string PropertyName; /********* @@ -24,13 +24,20 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters /// Construct an instance. /// The type whose field to which references should be rewritten. /// The field name to rewrite. - public FieldToPropertyRewriter(Type type, string fieldName) + /// The property name (if different). + public FieldToPropertyRewriter(Type type, string fieldName, string propertyName) : base(type.FullName, fieldName, InstructionHandleResult.None) { this.Type = type; - this.FieldName = fieldName; + this.PropertyName = propertyName; } + /// Construct an instance. + /// The type whose field to which references should be rewritten. + /// The field name to rewrite. + public FieldToPropertyRewriter(Type type, string fieldName) + : this(type, fieldName, fieldName) { } + /// Perform the predefined logic for an instruction if applicable. /// The assembly module containing the instruction. /// The CIL processor. @@ -43,8 +50,9 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters return InstructionHandleResult.None; string methodPrefix = instruction.OpCode == OpCodes.Ldsfld || instruction.OpCode == OpCodes.Ldfld ? "get" : "set"; - MethodReference propertyRef = module.Import(this.Type.GetMethod($"{methodPrefix}_{this.FieldName}")); + MethodReference propertyRef = module.Import(this.Type.GetMethod($"{methodPrefix}_{this.PropertyName}")); cil.Replace(instruction, cil.Create(OpCodes.Call, propertyRef)); + return InstructionHandleResult.Rewritten; } } diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StaticFieldToConstantRewriter.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StaticFieldToConstantRewriter.cs new file mode 100644 index 00000000..5e12b46a --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StaticFieldToConstantRewriter.cs @@ -0,0 +1,63 @@ +using System; +using Mono.Cecil; +using Mono.Cecil.Cil; +using StardewModdingAPI.Framework.ModLoading.Finders; + +namespace StardewModdingAPI.Framework.ModLoading.Rewriters +{ + /// Rewrites static field references into constant values. + /// The constant value type. + internal class StaticFieldToConstantRewriter : FieldFinder + { + /********* + ** Properties + *********/ + /// The constant value to replace with. + private readonly TValue Value; + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The type whose field to which references should be rewritten. + /// The field name to rewrite. + /// The constant value to replace with. + public StaticFieldToConstantRewriter(Type type, string fieldName, TValue value) + : base(type.FullName, fieldName, InstructionHandleResult.None) + { + this.Value = value; + } + + /// Perform the predefined logic for an instruction if applicable. + /// The assembly module containing the instruction. + /// The CIL processor. + /// The instruction to handle. + /// Metadata for mapping assemblies to the current platform. + /// Whether the mod was compiled on a different platform. + public override InstructionHandleResult Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, PlatformAssemblyMap assemblyMap, bool platformChanged) + { + if (!this.IsMatch(instruction)) + return InstructionHandleResult.None; + + cil.Replace(instruction, this.CreateConstantInstruction(cil, this.Value)); + return InstructionHandleResult.Rewritten; + } + + + /********* + ** Private methods + *********/ + /// Create a CIL constant value instruction. + /// The CIL processor. + /// The constant value to set. + private Instruction CreateConstantInstruction(ILProcessor cil, object value) + { + if (typeof(TValue) == typeof(int)) + return cil.Create(OpCodes.Ldc_I4, (int)value); + if (typeof(TValue) == typeof(string)) + return cil.Create(OpCodes.Ldstr, (string)value); + throw new NotSupportedException($"Rewriting to constant values of type {typeof(TValue)} isn't currently supported."); + } + } +} diff --git a/src/SMAPI/Metadata/InstructionMetadata.cs b/src/SMAPI/Metadata/InstructionMetadata.cs index 4ed1e38e..603a43cb 100644 --- a/src/SMAPI/Metadata/InstructionMetadata.cs +++ b/src/SMAPI/Metadata/InstructionMetadata.cs @@ -6,6 +6,9 @@ using StardewModdingAPI.Framework.ModLoading; using StardewModdingAPI.Framework.ModLoading.Finders; using StardewModdingAPI.Framework.ModLoading.Rewriters; using StardewValley; +#if STARDEW_VALLEY_1_3 +using SObject = StardewValley.Object; +#endif namespace StardewModdingAPI.Metadata { @@ -31,10 +34,11 @@ namespace StardewModdingAPI.Metadata /**** ** rewrite CIL to fix incompatible code ****/ - // crossplatform + // rewrite for crossplatform compatibility new MethodParentRewriter(typeof(SpriteBatch), typeof(SpriteBatchMethods), onlyIfPlatformChanged: true), - // Stardew Valley 1.2 +#if !STARDEW_VALLEY_1_3 + // rewrite for Stardew Valley 1.2 new FieldToPropertyRewriter(typeof(Game1), nameof(Game1.activeClickableMenu)), new FieldToPropertyRewriter(typeof(Game1), nameof(Game1.currentMinigame)), new FieldToPropertyRewriter(typeof(Game1), nameof(Game1.gameMode)), @@ -42,19 +46,33 @@ namespace StardewModdingAPI.Metadata new FieldReplaceRewriter(typeof(Game1), "borderFont", nameof(Game1.smallFont)), new FieldReplaceRewriter(typeof(Game1), "smoothFont", nameof(Game1.smallFont)), - // SMAPI 1.9 + // rewrite for SMAPI 1.9 new TypeReferenceRewriter("StardewModdingAPI.Inheritance.ItemStackChange", typeof(ItemStackChange)), +#endif - // SMAPI 2.0 - new VirtualEntryCallRemover(), // Mod.Entry changed from virtual to abstract in SMAPI 2.0, which breaks the few mods which called base.Entry() + // rewrite for SMAPI 2.0 + new VirtualEntryCallRemover(), + + // rewrite for Stardew Valley 1.3 +#if STARDEW_VALLEY_1_3 + new StaticFieldToConstantRewriter(typeof(Game1), "tileSize", Game1.tileSize), + new FieldToPropertyRewriter(typeof(Character), nameof(Character.name), nameof(Character.Name)), + new FieldToPropertyRewriter(typeof(GameLocation), nameof(GameLocation.isFarm), nameof(GameLocation.IsFarm)), + new FieldToPropertyRewriter(typeof(GameLocation), nameof(GameLocation.isOutdoors), nameof(GameLocation.isOutdoors)), + new FieldToPropertyRewriter(typeof(GameLocation), nameof(GameLocation.name), nameof(GameLocation.Name)), + new FieldToPropertyRewriter(typeof(Item), nameof(Item.category), nameof(Item.Category)), + new FieldToPropertyRewriter(typeof(SObject), nameof(SObject.quality), nameof(SObject.Quality)), + new FieldToPropertyRewriter(typeof(SObject), nameof(SObject.stack), nameof(SObject.Stack)), +#endif /**** ** detect incompatible code ****/ - // changes in Stardew Valley 1.2 (with no rewriters) + #if !STARDEW_VALLEY_1_3 + // detect changes in Stardew Valley 1.2 new FieldFinder("StardewValley.Item", "set_Name", InstructionHandleResult.NotCompatible), - // APIs removed in SMAPI 1.9 + // detect APIs removed in SMAPI 1.9 new TypeFinder("StardewModdingAPI.Advanced.ConfigFile", InstructionHandleResult.NotCompatible), new TypeFinder("StardewModdingAPI.Advanced.IConfigFile", InstructionHandleResult.NotCompatible), new TypeFinder("StardewModdingAPI.Entities.SPlayer", InstructionHandleResult.NotCompatible), @@ -71,7 +89,7 @@ namespace StardewModdingAPI.Metadata new EventFinder("StardewModdingAPI.Events.GraphicsEvents", "OnPreRenderHudEventNoCheck", InstructionHandleResult.NotCompatible), new EventFinder("StardewModdingAPI.Events.GraphicsEvents", "OnPreRenderGuiEventNoCheck", InstructionHandleResult.NotCompatible), - // APIs removed in SMAPI 2.0 + // detect APIs removed in SMAPI 2.0 new TypeFinder("StardewModdingAPI.Command", InstructionHandleResult.NotCompatible), new TypeFinder("StardewModdingAPI.Config", InstructionHandleResult.NotCompatible), new TypeFinder("StardewModdingAPI.Log", InstructionHandleResult.NotCompatible), @@ -93,8 +111,9 @@ namespace StardewModdingAPI.Metadata new PropertyFinder("StardewModdingAPI.Mod", "BaseConfigPath", InstructionHandleResult.NotCompatible), new PropertyFinder("StardewModdingAPI.Mod", "PerSaveConfigFolder", InstructionHandleResult.NotCompatible), new PropertyFinder("StardewModdingAPI.Mod", "PerSaveConfigPath", InstructionHandleResult.NotCompatible), + #endif - // broken code + // detect broken code new ReferenceToMissingMemberFinder(this.ValidateReferencesToAssemblies), new ReferenceToMemberWithUnexpectedTypeFinder(this.ValidateReferencesToAssemblies), diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj index 42bcb9a8..1dc7740e 100644 --- a/src/SMAPI/StardewModdingAPI.csproj +++ b/src/SMAPI/StardewModdingAPI.csproj @@ -112,6 +112,7 @@ + -- cgit