diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-07-08 19:03:59 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-08 19:03:59 -0400 |
commit | 795e8080635794eccd010b81110665b76535622e (patch) | |
tree | fbcd1c2472b08af686d18506c5ba38784a12b2d2 /src/SMAPI/Framework/ModLoading/AssemblyLoader.cs | |
parent | 1b25710cf26ccc46485c9475e33980a5490b9561 (diff) | |
parent | 1b3a1a48d0d0d7e2423db54f3266cabd80a5a9b3 (diff) | |
download | SMAPI-795e8080635794eccd010b81110665b76535622e.tar.gz SMAPI-795e8080635794eccd010b81110665b76535622e.tar.bz2 SMAPI-795e8080635794eccd010b81110665b76535622e.zip |
Merge pull request #852 from TehPers/TehPers/search-local-deps
Search assembly directory for dependencies
Diffstat (limited to 'src/SMAPI/Framework/ModLoading/AssemblyLoader.cs')
-rw-r--r-- | src/SMAPI/Framework/ModLoading/AssemblyLoader.cs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs index eb940c41..01037870 100644 --- a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs +++ b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs @@ -264,8 +264,15 @@ namespace StardewModdingAPI.Framework.ModLoading if (!file.Exists) yield break; // not a local assembly + // add the assembly's directory temporarily if needed + // this is needed by F# mods which bundle FSharp.Core.dll, for example + string? temporarySearchDir = null; + if (this.AssemblyDefinitionResolver.TryAddSearchDirectory(file.DirectoryName)) + temporarySearchDir = file.DirectoryName; + // read assembly AssemblyDefinition assembly; + try { byte[] assemblyBytes = File.ReadAllBytes(file.FullName); Stream readStream = this.TrackForDisposal(new MemoryStream(assemblyBytes)); @@ -286,6 +293,12 @@ namespace StardewModdingAPI.Framework.ModLoading assembly = this.TrackForDisposal(AssemblyDefinition.ReadAssembly(readStream, new ReaderParameters(ReadingMode.Immediate) { AssemblyResolver = assemblyResolver, InMemory = true })); } } + finally + { + // clean up temporary search directory + if (temporarySearchDir is not null) + this.AssemblyDefinitionResolver.RemoveSearchDirectory(temporarySearchDir); + } // skip if already visited if (visitedAssemblyNames.Contains(assembly.Name.Name)) |