diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-05-19 20:57:50 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-05-19 20:57:50 -0400 |
commit | 1838842bbc2db2d1049c193b8650bd101ba4858f (patch) | |
tree | 650c97b1d00091c53869323307705e78b3766275 /src/SMAPI/Framework/ModLoading/Finders/FieldFinder.cs | |
parent | f96dde00f98a913557617f716673f1af355cc6b5 (diff) | |
download | SMAPI-1838842bbc2db2d1049c193b8650bd101ba4858f.tar.gz SMAPI-1838842bbc2db2d1049c193b8650bd101ba4858f.tar.bz2 SMAPI-1838842bbc2db2d1049c193b8650bd101ba4858f.zip |
rewrite assembly rewriting, merge Harmony rewriters (#711)
This reduces duplication, decouples it from the assembly loader, and makes it more flexible to handle Harmony rewriting.
Diffstat (limited to 'src/SMAPI/Framework/ModLoading/Finders/FieldFinder.cs')
-rw-r--r-- | src/SMAPI/Framework/ModLoading/Finders/FieldFinder.cs | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/src/SMAPI/Framework/ModLoading/Finders/FieldFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/FieldFinder.cs index 9ae07916..c157ed9b 100644 --- a/src/SMAPI/Framework/ModLoading/Finders/FieldFinder.cs +++ b/src/SMAPI/Framework/ModLoading/Finders/FieldFinder.cs @@ -1,3 +1,4 @@ +using System; using Mono.Cecil; using Mono.Cecil.Cil; using StardewModdingAPI.Framework.ModLoading.Framework; @@ -28,39 +29,25 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders /// <param name="fieldName">The field name for which to find references.</param> /// <param name="result">The result to return for matching instructions.</param> public FieldFinder(string fullTypeName, string fieldName, InstructionHandleResult result) - : base(nounPhrase: $"{fullTypeName}.{fieldName} field") + : base(defaultPhrase: $"{fullTypeName}.{fieldName} field") { this.FullTypeName = fullTypeName; this.FieldName = fieldName; this.Result = result; } - /// <summary>Perform the predefined logic for an instruction if applicable.</summary> + /// <summary>Rewrite a CIL instruction reference if needed.</summary> /// <param name="module">The assembly module containing the instruction.</param> /// <param name="cil">The CIL processor.</param> /// <param name="instruction">The CIL instruction to handle.</param> - /// <param name="assemblyMap">Metadata for mapping assemblies to the current platform.</param> - /// <param name="platformChanged">Whether the mod was compiled on a different platform.</param> - public override InstructionHandleResult Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, PlatformAssemblyMap assemblyMap, bool platformChanged) + /// <param name="replaceWith">Replaces the CIL instruction with a new one.</param> + /// <returns>Returns whether the instruction was changed.</returns> + public override bool Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, Action<Instruction> replaceWith) { - return this.IsMatch(instruction) - ? this.Result - : InstructionHandleResult.None; - } - + if (!this.Flags.Contains(this.Result) && RewriteHelper.IsFieldReferenceTo(instruction, this.FullTypeName, this.FieldName)) + this.MarkFlag(this.Result); - /********* - ** Protected methods - *********/ - /// <summary>Get whether a CIL instruction matches.</summary> - /// <param name="instruction">The IL instruction.</param> - protected bool IsMatch(Instruction instruction) - { - FieldReference fieldRef = RewriteHelper.AsFieldReference(instruction); - return - fieldRef != null - && fieldRef.DeclaringType.FullName == this.FullTypeName - && fieldRef.Name == this.FieldName; + return false; } } } |