summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-08-08 00:21:28 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-08-08 00:21:28 -0400
commit885808fb66233caf3057f0baa6368f4763a8eade (patch)
treee6a996ca9068228d3f6fca8fa53db6dd7c9f6923 /src
parent5e16ed0eea2cae21badd525afa0d464700bb8647 (diff)
downloadSMAPI-885808fb66233caf3057f0baa6368f4763a8eade.tar.gz
SMAPI-885808fb66233caf3057f0baa6368f4763a8eade.tar.bz2
SMAPI-885808fb66233caf3057f0baa6368f4763a8eade.zip
move assembly resolver setup into Constants to centralize hardcoded logic
Diffstat (limited to 'src')
-rw-r--r--src/SMAPI/Constants.cs16
-rw-r--r--src/SMAPI/Framework/ModLoading/AssemblyLoader.cs4
2 files changed, 17 insertions, 3 deletions
diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs
index 6cbdeb8e..7f633a46 100644
--- a/src/SMAPI/Constants.cs
+++ b/src/SMAPI/Constants.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
+using Mono.Cecil;
using StardewModdingAPI.Enums;
using StardewModdingAPI.Framework;
using StardewModdingAPI.Framework.ModLoading;
@@ -229,6 +230,21 @@ namespace StardewModdingAPI
}
}
+ /// <summary>Configure the Mono.Cecil assembly resolver.</summary>
+ /// <param name="resolver">The assembly resolver.</param>
+ internal static void ConfigureAssemblyResolver(AssemblyDefinitionResolver resolver)
+ {
+ // add search paths
+ resolver.AddSearchDirectory(Constants.ExecutionPath);
+ resolver.AddSearchDirectory(Constants.InternalFilesPath);
+
+ // add SMAPI explicitly
+ // Normally this would be handled automatically by the search paths, but for some reason there's a specific
+ // case involving unofficial 64-bit Stardew Valley when launched through Steam (for some players only)
+ // where Mono.Cecil can't resolve references to SMAPI.
+ resolver.Add(AssemblyDefinition.ReadAssembly(typeof(SGame).Assembly.Location));
+ }
+
/// <summary>Get metadata for mapping assemblies to the current platform.</summary>
/// <param name="targetPlatform">The target game platform.</param>
/// <param name="framework">The game framework running the game.</param>
diff --git a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs
index 2b71038a..86b43990 100644
--- a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs
+++ b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs
@@ -59,9 +59,7 @@ namespace StardewModdingAPI.Framework.ModLoading
// init resolver
this.AssemblyDefinitionResolver = this.TrackForDisposal(new AssemblyDefinitionResolver());
- this.AssemblyDefinitionResolver.AddSearchDirectory(Constants.ExecutionPath);
- this.AssemblyDefinitionResolver.AddSearchDirectory(Constants.InternalFilesPath);
- this.AssemblyDefinitionResolver.Add(AssemblyDefinition.ReadAssembly(typeof(SGame).Assembly.Location)); // for some reason Mono.Cecil can't resolve SMAPI in very specific cases involving unofficial 64-bit Stardew Valley when launched through Steam (for some players only)
+ Constants.ConfigureAssemblyResolver(this.AssemblyDefinitionResolver);
// generate type => assembly lookup for types which should be rewritten
this.TypeAssemblies = new Dictionary<string, Assembly>();