summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-03-26 19:17:48 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-03-26 19:17:48 -0400
commit8bf3ef118a822afd1c7d7f80f6cf6eaeed346167 (patch)
tree75e51b9764337e06883c70d0bc93022bdeaadde2 /src/StardewModdingAPI/Framework
parent85ed48809032fdbb8461ce4c34acfbe06f68652b (diff)
downloadSMAPI-8bf3ef118a822afd1c7d7f80f6cf6eaeed346167.tar.gz
SMAPI-8bf3ef118a822afd1c7d7f80f6cf6eaeed346167.tar.bz2
SMAPI-8bf3ef118a822afd1c7d7f80f6cf6eaeed346167.zip
add support for rewriting method definitions (#254)
Diffstat (limited to 'src/StardewModdingAPI/Framework')
-rw-r--r--src/StardewModdingAPI/Framework/AssemblyLoader.cs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/StardewModdingAPI/Framework/AssemblyLoader.cs b/src/StardewModdingAPI/Framework/AssemblyLoader.cs
index 5d00c525..f6fe89f5 100644
--- a/src/StardewModdingAPI/Framework/AssemblyLoader.cs
+++ b/src/StardewModdingAPI/Framework/AssemblyLoader.cs
@@ -198,6 +198,26 @@ namespace StardewModdingAPI.Framework
IInstructionRewriter[] rewriters = Constants.GetRewriters().ToArray();
foreach (MethodDefinition method in this.GetMethods(module))
{
+ // check method definition
+ foreach (IInstructionRewriter rewriter in rewriters)
+ {
+ try
+ {
+ if (rewriter.Rewrite(module, method, this.AssemblyMap, platformChanged))
+ {
+ this.LogOnce(this.Monitor, loggedMessages, $"Rewrote {assembly.Name.Name} to fix {rewriter.NounPhrase}...");
+ anyRewritten = true;
+ }
+ }
+ catch (IncompatibleInstructionException)
+ {
+ if (!assumeCompatible)
+ throw new IncompatibleInstructionException(rewriter.NounPhrase, $"Found an incompatible CIL instruction ({rewriter.NounPhrase}) while loading assembly {assembly.Name.Name}.");
+ this.LogOnce(this.Monitor, loggedMessages, $"Found an incompatible CIL instruction ({rewriter.NounPhrase}) while loading assembly {assembly.Name.Name}, but SMAPI is configured to allow it anyway. The mod may crash or behave unexpectedly.", LogLevel.Warn);
+ }
+ }
+
+ // check CIL instructions
ILProcessor cil = method.Body.GetILProcessor();
foreach (Instruction instruction in cil.Body.Instructions.ToArray())
{