summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI
diff options
context:
space:
mode:
Diffstat (limited to 'src/StardewModdingAPI')
-rw-r--r--src/StardewModdingAPI/Framework/AssemblyRewriting/AssemblyTypeRewriter.cs21
-rw-r--r--src/StardewModdingAPI/Framework/ModAssemblyLoader.cs2
2 files changed, 14 insertions, 9 deletions
diff --git a/src/StardewModdingAPI/Framework/AssemblyRewriting/AssemblyTypeRewriter.cs b/src/StardewModdingAPI/Framework/AssemblyRewriting/AssemblyTypeRewriter.cs
index 7a339266..2bfb43e4 100644
--- a/src/StardewModdingAPI/Framework/AssemblyRewriting/AssemblyTypeRewriter.cs
+++ b/src/StardewModdingAPI/Framework/AssemblyRewriting/AssemblyTypeRewriter.cs
@@ -65,24 +65,29 @@ namespace StardewModdingAPI.Framework.AssemblyRewriting
foreach (ModuleDefinition module in assembly.Modules)
{
// remove old assembly references
+ bool shouldRewrite = false;
for (int i = 0; i < module.AssemblyReferences.Count; i++)
{
- bool shouldRemove = this.RemoveAssemblyNames.Any(name => module.AssemblyReferences[i].Name == name) || this.TargetAssemblies.Any(a => module.AssemblyReferences[i].Name == a.GetName().Name);
+ bool shouldRemove = this.RemoveAssemblyNames.Any(name => module.AssemblyReferences[i].Name == name);
if (shouldRemove)
{
+ shouldRewrite = true;
module.AssemblyReferences.RemoveAt(i);
i--;
}
}
- // add target assembly references
- foreach (AssemblyNameReference target in this.AssemblyNameReferences.Values)
- module.AssemblyReferences.Add(target);
+ // replace references
+ if (shouldRewrite)
+ {
+ // add target assembly references
+ foreach (AssemblyNameReference target in this.AssemblyNameReferences.Values)
+ module.AssemblyReferences.Add(target);
- // rewrite type scopes to use target assemblies
- TypeReference[] refs = (TypeReference[])module.GetTypeReferences();
- foreach (TypeReference type in refs)
- this.ChangeTypeScope(type);
+ // rewrite type scopes to use target assemblies
+ foreach (TypeReference type in module.GetTypeReferences())
+ this.ChangeTypeScope(type);
+ }
}
}
diff --git a/src/StardewModdingAPI/Framework/ModAssemblyLoader.cs b/src/StardewModdingAPI/Framework/ModAssemblyLoader.cs
index 264d1ff2..54a111d3 100644
--- a/src/StardewModdingAPI/Framework/ModAssemblyLoader.cs
+++ b/src/StardewModdingAPI/Framework/ModAssemblyLoader.cs
@@ -94,7 +94,7 @@ namespace StardewModdingAPI.Framework
CachePaths cachePaths = this.GetCacheInfo(assemblyPath);
if (!File.Exists(cachePaths.Assembly))
throw new InvalidOperationException($"The assembly {assemblyPath} doesn't exist in the preprocessed cache.");
- return Assembly.UnsafeLoadFrom(cachePaths.Assembly);
+ return Assembly.UnsafeLoadFrom(cachePaths.Assembly); // unsafe load allows DLLs downloaded from the Internet without the user needing to 'unblock' them
}