summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2016-11-27 12:08:00 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2016-11-27 12:08:00 -0500
commit8917fb6697b5eae0c14bcf2437aef7e9a8d51abb (patch)
treec869aec8f23c8177103d6495854addef35d8485d /src/StardewModdingAPI
parent2e40ad7ad3d83970969b160eae87fc9aa4608916 (diff)
downloadSMAPI-8917fb6697b5eae0c14bcf2437aef7e9a8d51abb.tar.gz
SMAPI-8917fb6697b5eae0c14bcf2437aef7e9a8d51abb.tar.bz2
SMAPI-8917fb6697b5eae0c14bcf2437aef7e9a8d51abb.zip
only rewrite assemblies if needed (#166)
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
}