From 95f4513727193d0048848d10ded465527a4969c9 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 16 Jan 2022 22:56:48 -0500 Subject: rewrite fallback assembly resolution * SMAPI now also searches the root game folder for unresolved assemblies. This fixes an issue resolving the game DLL when the player's DLL version doesn't match the one used to compile SMAPI. * The DLL search folders are now scanned once and cached to avoid repeated iterations on startup. --- src/SMAPI/Program.cs | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs index 67ff8322..0c90f2aa 100644 --- a/src/SMAPI/Program.cs +++ b/src/SMAPI/Program.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; @@ -16,7 +17,10 @@ namespace StardewModdingAPI ** Fields *********/ /// The absolute path to search for SMAPI's internal DLLs. - internal static readonly string DllSearchPath = EarlyConstants.InternalFilesPath; + private static readonly string DllSearchPath = EarlyConstants.InternalFilesPath; + + /// The assembly paths in the search folders indexed by assembly name. + private static Dictionary AssemblyPathsByName; /********* @@ -57,16 +61,36 @@ namespace StardewModdingAPI /// The event arguments. private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs e) { - try + // cache assembly paths by name + if (Program.AssemblyPathsByName == null) { - AssemblyName name = new AssemblyName(e.Name); - foreach (FileInfo dll in new DirectoryInfo(Program.DllSearchPath).EnumerateFiles("*.dll")) + Program.AssemblyPathsByName = new(StringComparer.OrdinalIgnoreCase); + + foreach (string searchPath in new[] { EarlyConstants.ExecutionPath, Program.DllSearchPath }) { - if (name.Name.Equals(AssemblyName.GetAssemblyName(dll.FullName).Name, StringComparison.OrdinalIgnoreCase)) - return Assembly.LoadFrom(dll.FullName); + foreach (string dllPath in Directory.EnumerateFiles(searchPath, "*.dll")) + { + try + { + string curName = AssemblyName.GetAssemblyName(dllPath).Name; + if (curName != null) + Program.AssemblyPathsByName[curName] = dllPath; + } + catch + { + continue; + } + } } + } - return null; + // resolve + try + { + string searchName = new AssemblyName(e.Name).Name; + return searchName != null && Program.AssemblyPathsByName.TryGetValue(searchName, out string assemblyPath) + ? Assembly.LoadFrom(assemblyPath) + : null; } catch (Exception ex) { -- cgit From dbed0289d7b7759145dea3e1c5d93df3d68ff116 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 16 Jan 2022 22:57:40 -0500 Subject: prepare for release --- build/common.targets | 2 +- docs/release-notes.md | 7 +++++-- src/SMAPI.Mods.ConsoleCommands/manifest.json | 4 ++-- src/SMAPI.Mods.ErrorHandler/manifest.json | 4 ++-- src/SMAPI.Mods.SaveBackup/manifest.json | 4 ++-- src/SMAPI/Constants.cs | 2 +- 6 files changed, 13 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/build/common.targets b/build/common.targets index 8eac9757..86624b62 100644 --- a/build/common.targets +++ b/build/common.targets @@ -1,7 +1,7 @@ - 3.13.3 + 3.13.4 SMAPI latest $(AssemblySearchPaths);{GAC} diff --git a/docs/release-notes.md b/docs/release-notes.md index 684fb49d..05ab58a3 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -1,8 +1,11 @@ ← [README](README.md) # Release notes -## Upcoming release -* Fixed Linux/macOS launch error in 3.13.3. +## 3.13.4 +Released 16 January 2022 for Stardew Valley 1.5.6 or later. + +* For players: + * Fixed Linux/macOS launch error in 3.13.3. ## 3.13.3 Released 16 January 2022 for Stardew Valley 1.5.6 or later. diff --git a/src/SMAPI.Mods.ConsoleCommands/manifest.json b/src/SMAPI.Mods.ConsoleCommands/manifest.json index 97e1c243..fa5f6d6f 100644 --- a/src/SMAPI.Mods.ConsoleCommands/manifest.json +++ b/src/SMAPI.Mods.ConsoleCommands/manifest.json @@ -1,9 +1,9 @@ { "Name": "Console Commands", "Author": "SMAPI", - "Version": "3.13.3", + "Version": "3.13.4", "Description": "Adds SMAPI console commands that let you manipulate the game.", "UniqueID": "SMAPI.ConsoleCommands", "EntryDll": "ConsoleCommands.dll", - "MinimumApiVersion": "3.13.3" + "MinimumApiVersion": "3.13.4" } diff --git a/src/SMAPI.Mods.ErrorHandler/manifest.json b/src/SMAPI.Mods.ErrorHandler/manifest.json index c4246721..11bc0b42 100644 --- a/src/SMAPI.Mods.ErrorHandler/manifest.json +++ b/src/SMAPI.Mods.ErrorHandler/manifest.json @@ -1,9 +1,9 @@ { "Name": "Error Handler", "Author": "SMAPI", - "Version": "3.13.3", + "Version": "3.13.4", "Description": "Handles some common vanilla errors to log more useful info or avoid breaking the game.", "UniqueID": "SMAPI.ErrorHandler", "EntryDll": "ErrorHandler.dll", - "MinimumApiVersion": "3.13.3" + "MinimumApiVersion": "3.13.4" } diff --git a/src/SMAPI.Mods.SaveBackup/manifest.json b/src/SMAPI.Mods.SaveBackup/manifest.json index b1b946c8..c50cff14 100644 --- a/src/SMAPI.Mods.SaveBackup/manifest.json +++ b/src/SMAPI.Mods.SaveBackup/manifest.json @@ -1,9 +1,9 @@ { "Name": "Save Backup", "Author": "SMAPI", - "Version": "3.13.3", + "Version": "3.13.4", "Description": "Automatically backs up all your saves once per day into its folder.", "UniqueID": "SMAPI.SaveBackup", "EntryDll": "SaveBackup.dll", - "MinimumApiVersion": "3.13.3" + "MinimumApiVersion": "3.13.4" } diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index 455cfd7e..667491d6 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -49,7 +49,7 @@ namespace StardewModdingAPI internal static int? LogScreenId { get; set; } /// SMAPI's current raw semantic version. - internal static string RawApiVersion = "3.13.3"; + internal static string RawApiVersion = "3.13.4"; } /// Contains SMAPI's constants and assumptions. -- cgit