summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-03-03 22:03:41 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-03-03 22:03:41 -0500
commitf9dc901994c1a8b17e22de3f68ceb038965e0cc5 (patch)
treeb4e1694f4891376ad244ecb48edae47f4d7088e7 /src
parent47b9c5995e56fc8424dfeb4151d33a1080d3fc2b (diff)
downloadSMAPI-f9dc901994c1a8b17e22de3f68ceb038965e0cc5.tar.gz
SMAPI-f9dc901994c1a8b17e22de3f68ceb038965e0cc5.tar.bz2
SMAPI-f9dc901994c1a8b17e22de3f68ceb038965e0cc5.zip
fix error in new incompatibility finders when they resolve members in a dependency (#453)
Diffstat (limited to 'src')
-rw-r--r--src/SMAPI/Framework/ModLoading/AssemblyDefinitionResolver.cs2
-rw-r--r--src/SMAPI/Framework/ModLoading/AssemblyLoader.cs24
2 files changed, 17 insertions, 9 deletions
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
*********/
+ /// <summary>Encapsulates monitoring and logging.</summary>
+ private readonly IMonitor Monitor;
+
+ /// <summary>Whether to enable developer mode logging.</summary>
+ private readonly bool IsDeveloperMode;
+
/// <summary>Metadata for mapping assemblies to the current platform.</summary>
private readonly PlatformAssemblyMap AssemblyMap;
/// <summary>A type => assembly lookup for types which should be rewritten.</summary>
private readonly IDictionary<string, Assembly> TypeAssemblies;
- /// <summary>Encapsulates monitoring and logging.</summary>
- private readonly IMonitor Monitor;
-
- /// <summary>Whether to enable developer mode logging.</summary>
- private readonly bool IsDeveloperMode;
+ /// <summary>A minimal assembly definition resolver which resolves references to known loaded assemblies.</summary>
+ 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<string, Assembly>();
@@ -69,9 +73,8 @@ namespace StardewModdingAPI.Framework.ModLoading
// get referenced local assemblies
AssemblyParseResult[] assemblies;
{
- AssemblyDefinitionResolver resolver = new AssemblyDefinitionResolver();
HashSet<string> visitedAssemblyNames = new HashSet<string>(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