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/SMAPI/Framework/ModLoading/AssemblyLoader.cs | |
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/SMAPI/Framework/ModLoading/AssemblyLoader.cs')
-rw-r--r-- | src/SMAPI/Framework/ModLoading/AssemblyLoader.cs | 30 |
1 files changed, 5 insertions, 25 deletions
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 { |