summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/Patching/PatchHelper.cs
blob: 4cb436f0aa9c90ef35d97b07da33095892188f5d (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
using System;
using System.Collections.Generic;

namespace StardewModdingAPI.Framework.Patching
{
    /// <summary>Provides generic methods for implementing Harmony patches.</summary>
    internal class PatchHelper
    {
        /*********
        ** Fields
        *********/
        /// <summary>The interception keys currently being intercepted.</summary>
        private static readonly HashSet<string> InterceptingKeys = new HashSet<string>(StringComparer.OrdinalIgnoreCase);


        /*********
        ** Public methods
        *********/
        /// <summary>Track a method that will be intercepted.</summary>
        /// <param name="key">The intercept key.</param>
        /// <returns>Returns false if the method was already marked for interception, else true.</returns>
        public static bool StartIntercept(string key)
        {
            return PatchHelper.InterceptingKeys.Add(key);
        }

        /// <summary>Track a method as no longer being intercepted.</summary>
        /// <param name="key">The intercept key.</param>
        public static void StopIntercept(string key)
        {
            PatchHelper.InterceptingKeys.Remove(key);
        }
    }
}