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) --- .../Finders/ReferenceToMissingMemberFinder.cs | 87 ++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs (limited to 'src/SMAPI/Framework/ModLoading/Finders') 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_"); + } + } +} -- 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/Finders') 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/Finders') 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/Finders') 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