using Mono.Cecil;
using Mono.Cecil.Cil;
namespace StardewModdingAPI.AssemblyRewriters.Framework
{
/// Base class for a field finder.
public abstract class BaseFieldFinder : IInstructionFinder
{
/*********
** Accessors
*********/
/// A brief noun phrase indicating what the instruction finder matches.
public abstract string NounPhrase { get; }
/*********
** Public methods
*********/
/// Get whether a CIL instruction matches.
/// The IL instruction.
/// Whether the mod was compiled on a different platform.
public bool IsMatch(Instruction instruction, bool platformChanged)
{
if (instruction.OpCode != OpCodes.Ldfld && instruction.OpCode != OpCodes.Ldsfld && instruction.OpCode != OpCodes.Stfld && instruction.OpCode != OpCodes.Stsfld)
return false; // not a field reference
return this.IsMatch(instruction, (FieldReference)instruction.Operand, platformChanged);
}
/*********
** Protected methods
*********/
/// Get whether a field reference should be rewritten.
/// The IL instruction.
/// The field reference.
/// Whether the mod was compiled on a different platform.
protected abstract bool IsMatch(Instruction instruction, FieldReference fieldRef, bool platformChanged);
/// Whether an instruction is a static field reference.
/// The IL instruction.
protected bool IsStaticField(Instruction instruction)
{
return instruction.OpCode == OpCodes.Ldsfld || instruction.OpCode == OpCodes.Stsfld;
}
}
}