summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework/AssemblyLoader.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/StardewModdingAPI/Framework/AssemblyLoader.cs')
-rw-r--r--src/StardewModdingAPI/Framework/AssemblyLoader.cs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/StardewModdingAPI/Framework/AssemblyLoader.cs b/src/StardewModdingAPI/Framework/AssemblyLoader.cs
index 8af67772..dfe0d03f 100644
--- a/src/StardewModdingAPI/Framework/AssemblyLoader.cs
+++ b/src/StardewModdingAPI/Framework/AssemblyLoader.cs
@@ -55,6 +55,7 @@ namespace StardewModdingAPI.Framework
/// <summary>Preprocess and load an assembly.</summary>
/// <param name="assemblyPath">The assembly file path.</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)
{
// get referenced local assemblies
@@ -159,6 +160,7 @@ namespace StardewModdingAPI.Framework
/// <summary>Rewrite the types referenced by an assembly.</summary>
/// <param name="assembly">The assembly to rewrite.</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)
{
ModuleDefinition module = assembly.MainModule;
@@ -189,6 +191,22 @@ namespace StardewModdingAPI.Framework
this.ChangeTypeScope(type);
}
+ // throw exception if assembly contains incompatible instructions can't be rewritten
+ {
+ IInstructionFinder[] finders = Constants.GetIncompatibilityFinders().ToArray();
+ foreach (MethodDefinition method in this.GetMethods(module))
+ {
+ foreach (Instruction instruction in method.Body.Instructions)
+ {
+ foreach (IInstructionFinder finder in finders)
+ {
+ if (finder.IsMatch(instruction, platformChanged))
+ throw new IncompatibleInstructionException(finder.NounPhrase, $"Found an incompatible CIL instruction ({finder.NounPhrase}) while loading assembly {assembly.Name.Name}.");
+ }
+ }
+ }
+ }
+
// rewrite incompatible instructions
bool anyRewritten = false;
IInstructionRewriter[] rewriters = Constants.GetRewriters().ToArray();