summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ModLoading/Rewriters
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Framework/ModLoading/Rewriters')
-rw-r--r--src/SMAPI/Framework/ModLoading/Rewriters/FieldReplaceRewriter.cs4
-rw-r--r--src/SMAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs5
-rw-r--r--src/SMAPI/Framework/ModLoading/Rewriters/StaticFieldToConstantRewriter.cs30
3 files changed, 18 insertions, 21 deletions
diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/FieldReplaceRewriter.cs b/src/SMAPI/Framework/ModLoading/Rewriters/FieldReplaceRewriter.cs
index 2b8fbe06..c251a30c 100644
--- a/src/SMAPI/Framework/ModLoading/Rewriters/FieldReplaceRewriter.cs
+++ b/src/SMAPI/Framework/ModLoading/Rewriters/FieldReplaceRewriter.cs
@@ -58,8 +58,8 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters
return false;
// replace with new field
- FieldReference newRef = module.ImportReference(this.ToField);
- replaceWith(cil.Create(instruction.OpCode, newRef));
+ instruction.Operand = module.ImportReference(this.ToField);
+
return this.MarkRewritten();
}
}
diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs b/src/SMAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs
index de123cc2..0a99bde0 100644
--- a/src/SMAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs
+++ b/src/SMAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs
@@ -49,8 +49,9 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters
return false;
// rewrite field to property
- MethodReference propertyRef = module.ImportReference(method);
- replaceWith(cil.Create(OpCodes.Call, propertyRef));
+ instruction.OpCode = OpCodes.Call;
+ instruction.Operand = module.ImportReference(method);
+
this.Phrases.Add($"{fieldRef.DeclaringType.Name}.{fieldRef.Name} (field => property)");
return this.MarkRewritten();
}
diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StaticFieldToConstantRewriter.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StaticFieldToConstantRewriter.cs
index 6ea59d1c..2f1122b4 100644
--- a/src/SMAPI/Framework/ModLoading/Rewriters/StaticFieldToConstantRewriter.cs
+++ b/src/SMAPI/Framework/ModLoading/Rewriters/StaticFieldToConstantRewriter.cs
@@ -46,24 +46,20 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters
return false;
// rewrite to constant
- replaceWith(this.CreateConstantInstruction(cil, this.Value));
- return this.MarkRewritten();
- }
-
-
- /*********
- ** Private methods
- *********/
- /// <summary>Create a CIL constant value instruction.</summary>
- /// <param name="cil">The CIL processor.</param>
- /// <param name="value">The constant value to set.</param>
- private Instruction CreateConstantInstruction(ILProcessor cil, object value)
- {
if (typeof(TValue) == typeof(int))
- return cil.Create(OpCodes.Ldc_I4, (int)value);
- if (typeof(TValue) == typeof(string))
- return cil.Create(OpCodes.Ldstr, (string)value);
- throw new NotSupportedException($"Rewriting to constant values of type {typeof(TValue)} isn't currently supported.");
+ {
+ instruction.OpCode = OpCodes.Ldc_I4;
+ instruction.Operand = this.Value;
+ }
+ else if (typeof(TValue) == typeof(string))
+ {
+ instruction.OpCode = OpCodes.Ldstr;
+ instruction.Operand = this.Value;
+ }
+ else
+ throw new NotSupportedException($"Rewriting to constant values of type {typeof(TValue)} isn't currently supported.");
+
+ return this.MarkRewritten();
}
}
}