diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-05-18 17:26:47 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-05-18 17:26:47 -0400 |
commit | 21303a4e987e4169f3bf0c55c7099d0d07536ca5 (patch) | |
tree | 5447b3406004573aafadd5bd9f4d8c5186b73888 /src | |
parent | b34d7470e2769a50e87a33e1cb3a8da637a2f143 (diff) | |
download | SMAPI-21303a4e987e4169f3bf0c55c7099d0d07536ca5.tar.gz SMAPI-21303a4e987e4169f3bf0c55c7099d0d07536ca5.tar.bz2 SMAPI-21303a4e987e4169f3bf0c55c7099d0d07536ca5.zip |
remove workaround no longer needed with Harmony 2.0.2 (#711)
Diffstat (limited to 'src')
-rw-r--r-- | src/SMAPI/Constants.cs | 3 | ||||
-rw-r--r-- | src/SMAPI/Framework/ModLoading/AssemblyLoader.cs | 30 | ||||
-rw-r--r-- | src/SMAPI/Framework/SCore.cs | 16 |
3 files changed, 6 insertions, 43 deletions
diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index 907a93b2..a898fccd 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -61,9 +61,6 @@ namespace StardewModdingAPI /// <summary>The absolute path to the folder containing SMAPI's internal files.</summary> internal static readonly string InternalFilesPath = Program.DllSearchPath; - /// <summary>The folder containing temporary files that are only valid for the current session.</summary> - internal static string InternalTempFilesPath => Path.Combine(Program.DllSearchPath, ".temp"); - /// <summary>The file path for the SMAPI configuration file.</summary> internal static string ApiConfigPath => Path.Combine(Constants.InternalFilesPath, "config.json"); diff --git a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs index 78e717e9..b95a45b5 100644 --- a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs +++ b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs @@ -36,9 +36,6 @@ namespace StardewModdingAPI.Framework.ModLoading /// <summary>The objects to dispose as part of this instance.</summary> private readonly HashSet<IDisposable> Disposables = new HashSet<IDisposable>(); - /// <summary>The full path to the folder in which to save rewritten assemblies.</summary> - private readonly string TempFolderPath; - /********* ** Public methods @@ -47,13 +44,11 @@ namespace StardewModdingAPI.Framework.ModLoading /// <param name="targetPlatform">The current game platform.</param> /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="paranoidMode">Whether to detect paranoid mode issues.</param> - /// <param name="tempFolderPath">The full path to the folder in which to save rewritten assemblies.</param> - public AssemblyLoader(Platform targetPlatform, IMonitor monitor, bool paranoidMode, string tempFolderPath) + public AssemblyLoader(Platform targetPlatform, IMonitor monitor, bool paranoidMode) { this.Monitor = monitor; this.ParanoidMode = paranoidMode; this.AssemblyMap = this.TrackForDisposal(Constants.GetAssemblyMap(targetPlatform)); - this.TempFolderPath = tempFolderPath; // init resolver this.AssemblyDefinitionResolver = this.TrackForDisposal(new AssemblyDefinitionResolver()); @@ -133,25 +128,10 @@ namespace StardewModdingAPI.Framework.ModLoading if (!oneAssembly) this.Monitor.Log($" Loading {assembly.File.Name} (rewritten)...", LogLevel.Trace); - if (assembly.Definition.MainModule.AssemblyReferences.Any(p => p.Name == "0Harmony")) - { - // Note: the assembly must be loaded from disk for Harmony compatibility. - // Loading it from memory sets the assembly module's FullyQualifiedName to - // "<Unknown>", so Harmony incorrectly identifies the module in its - // Patch.PatchMethod when handling multiple patches for the same method, - // leading to "Token 0x... is not valid in the scope of module HarmonySharedState" - // errors (e.g. https://smapi.io/log/A0gAsc3M). - string tempPath = Path.Combine(this.TempFolderPath, $"{Path.GetFileNameWithoutExtension(assemblyPath)}.{Guid.NewGuid()}.dll"); - assembly.Definition.Write(tempPath); - lastAssembly = Assembly.LoadFile(tempPath); - } - else - { - using MemoryStream outStream = new MemoryStream(); - assembly.Definition.Write(outStream); - byte[] bytes = outStream.ToArray(); - lastAssembly = Assembly.Load(bytes); - } + using MemoryStream outStream = new MemoryStream(); + assembly.Definition.Write(outStream); + byte[] bytes = outStream.ToArray(); + lastAssembly = Assembly.Load(bytes); } else { diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 12dc9c3d..de9c955d 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -213,20 +213,6 @@ namespace StardewModdingAPI.Framework return; } #endif - - // reset temp folder - if (Directory.Exists(Constants.InternalTempFilesPath)) - { - try - { - FileUtilities.ForceDelete(new DirectoryInfo(Constants.InternalTempFilesPath)); - } - catch (Exception ex) - { - this.Monitor.Log($"Couldn't delete temporary files at {Constants.InternalTempFilesPath}: {ex}", LogLevel.Trace); - } - } - Directory.CreateDirectory(Constants.InternalTempFilesPath); } /// <summary>Launch SMAPI.</summary> @@ -762,7 +748,7 @@ namespace StardewModdingAPI.Framework // load mods IDictionary<IModMetadata, Tuple<string, string>> skippedMods = new Dictionary<IModMetadata, Tuple<string, string>>(); - using (AssemblyLoader modAssemblyLoader = new AssemblyLoader(Constants.Platform, this.Monitor, this.Settings.ParanoidWarnings, Constants.InternalTempFilesPath)) + using (AssemblyLoader modAssemblyLoader = new AssemblyLoader(Constants.Platform, this.Monitor, this.Settings.ParanoidWarnings)) { // init HashSet<string> suppressUpdateChecks = new HashSet<string>(this.Settings.SuppressUpdateChecks, StringComparer.InvariantCultureIgnoreCase); |