diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-09-19 22:52:52 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-09-19 22:52:52 -0400 |
commit | c513bb011c858e59abbd77f75080f4a1d8b712f9 (patch) | |
tree | 1ba22b78c0a0e9d3915fb4d2d6378eff0e1ae532 /src/StardewModdingAPI/Framework/ModLoading/AssemblyLoader.cs | |
parent | 954de8c4f2683b39a3f5a11fd29c39130bc31bdb (diff) | |
download | SMAPI-c513bb011c858e59abbd77f75080f4a1d8b712f9.tar.gz SMAPI-c513bb011c858e59abbd77f75080f4a1d8b712f9.tar.bz2 SMAPI-c513bb011c858e59abbd77f75080f4a1d8b712f9.zip |
pass mod metadata into rewriters (#347)
Diffstat (limited to 'src/StardewModdingAPI/Framework/ModLoading/AssemblyLoader.cs')
-rw-r--r-- | src/StardewModdingAPI/Framework/ModLoading/AssemblyLoader.cs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/StardewModdingAPI/Framework/ModLoading/AssemblyLoader.cs b/src/StardewModdingAPI/Framework/ModLoading/AssemblyLoader.cs index 01dc602a..f9c43f1f 100644 --- a/src/StardewModdingAPI/Framework/ModLoading/AssemblyLoader.cs +++ b/src/StardewModdingAPI/Framework/ModLoading/AssemblyLoader.cs @@ -53,11 +53,12 @@ namespace StardewModdingAPI.Framework.ModLoading } /// <summary>Preprocess and load an assembly.</summary> + /// <param name="mod">The mod for which the assembly is being loaded.</param> /// <param name="assemblyPath">The assembly file path.</param> /// <param name="assumeCompatible">Assume the mod is compatible, even if incompatible code is detected.</param> /// <returns>Returns the rewrite metadata for the preprocessed assembly.</returns> /// <exception cref="IncompatibleInstructionException">An incompatible CIL instruction was found while rewriting the assembly.</exception> - public Assembly Load(string assemblyPath, bool assumeCompatible) + public Assembly Load(IModMetadata mod, string assemblyPath, bool assumeCompatible) { // get referenced local assemblies AssemblyParseResult[] assemblies; @@ -86,7 +87,7 @@ namespace StardewModdingAPI.Framework.ModLoading if (assembly.Status == AssemblyLoadStatus.AlreadyLoaded) continue; - bool changed = this.RewriteAssembly(assembly.Definition, assumeCompatible, logPrefix: " "); + bool changed = this.RewriteAssembly(mod, assembly.Definition, assumeCompatible, logPrefix: " "); if (changed) { if (!oneAssembly) @@ -173,12 +174,13 @@ namespace StardewModdingAPI.Framework.ModLoading ** Assembly rewriting ****/ /// <summary>Rewrite the types referenced by an assembly.</summary> + /// <param name="mod">The mod for which the assembly is being loaded.</param> /// <param name="assembly">The assembly to rewrite.</param> /// <param name="assumeCompatible">Assume the mod is compatible, even if incompatible code is detected.</param> /// <param name="logPrefix">A string to prefix to log messages.</param> /// <returns>Returns whether the assembly was modified.</returns> /// <exception cref="IncompatibleInstructionException">An incompatible CIL instruction was found while rewriting the assembly.</exception> - private bool RewriteAssembly(AssemblyDefinition assembly, bool assumeCompatible, string logPrefix) + private bool RewriteAssembly(IModMetadata mod, AssemblyDefinition assembly, bool assumeCompatible, string logPrefix) { ModuleDefinition module = assembly.MainModule; HashSet<string> loggedMessages = new HashSet<string>(); @@ -211,7 +213,7 @@ namespace StardewModdingAPI.Framework.ModLoading // find (and optionally rewrite) incompatible instructions bool anyRewritten = false; - IInstructionRewriter[] rewriters = Constants.GetRewriters().ToArray(); + IInstructionRewriter[] rewriters = Constants.GetRewriters(this.Monitor).ToArray(); foreach (MethodDefinition method in this.GetMethods(module)) { // check method definition @@ -219,7 +221,7 @@ namespace StardewModdingAPI.Framework.ModLoading { try { - if (rewriter.Rewrite(module, method, this.AssemblyMap, platformChanged)) + if (rewriter.Rewrite(mod, module, method, this.AssemblyMap, platformChanged)) { this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Rewrote {filename} to fix {rewriter.NounPhrase}..."); anyRewritten = true; @@ -241,7 +243,7 @@ namespace StardewModdingAPI.Framework.ModLoading { try { - if (rewriter.Rewrite(module, cil, instruction, this.AssemblyMap, platformChanged)) + if (rewriter.Rewrite(mod, module, cil, instruction, this.AssemblyMap, platformChanged)) { this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Rewrote {filename} to fix {rewriter.NounPhrase}..."); anyRewritten = true; |