summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ModLoading/IInstructionHandler.cs
blob: e6de67859dcc6fa7e027ae70e6e7e6690e7220b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Collections.Generic;
using Mono.Cecil;
using Mono.Cecil.Cil;

namespace StardewModdingAPI.Framework.ModLoading
{
    /// <summary>Performs predefined logic for detected CIL instructions.</summary>
    internal interface IInstructionHandler
    {
        /*********
        ** Accessors
        *********/
        /// <summary>A brief noun phrase indicating what the handler matches, used if <see cref="Phrases"/> is empty.</summary>
        string DefaultPhrase { get; }

        /// <summary>The rewrite flags raised for the current module.</summary>
        ISet<InstructionHandleResult> Flags { get; }

        /// <summary>The brief noun phrases indicating what the handler matched for the current module.</summary>
        ISet<string> Phrases { get; }


        /*********
        ** Methods
        *********/
        /// <summary>Rewrite a type reference if needed.</summary>
        /// <param name="module">The assembly module containing the instruction.</param>
        /// <param name="type">The type definition to handle.</param>
        /// <param name="replaceWith">Replaces the type reference with a new one.</param>
        /// <returns>Returns whether the type was changed.</returns>
        bool Handle(ModuleDefinition module, TypeReference type, Action<TypeReference> replaceWith);

        /// <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="replaceWith">Replaces the CIL instruction with a new one.</param>
        /// <returns>Returns whether the instruction was changed.</returns>
        bool Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, Action<Instruction> replaceWith);
    }
}