三国卡牌客户端基础资源仓库
hch
2025-06-20 4841e82bd5e399c4fc39313bbc93c6fc1bb12b2a
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using System.Linq;
using System.IO;
#if UNITY_EDITOR
using UnityEditor;
#endif
 
namespace MonoHook
{
    /// <summary>
    /// Hook 池,防止重复 Hook
    /// </summary>
    public static class HookPool
    {
        private static Dictionary<MethodBase, MethodHook> _hooks = new Dictionary<MethodBase, MethodHook>();
 
        public static void AddHook(MethodBase method, MethodHook hook)
        {
            MethodHook preHook;
            if (_hooks.TryGetValue(method, out preHook))
            {
                preHook.Uninstall();
                _hooks[method] = hook;
            }
            else
                _hooks.Add(method, hook);
        }
 
        public static MethodHook GetHook(MethodBase method)
        {
            if (method == null) return null;
 
            MethodHook hook;
            if (_hooks.TryGetValue(method, out hook))
                return hook;
            return null;
        }
 
        public static void RemoveHooker(MethodBase method)
        {
            if (method == null) return;
 
            _hooks.Remove(method);
        }
 
        public static void UninstallAll()
        {
            var list = _hooks.Values.ToList();
            foreach (var hook in list)
                hook.Uninstall();
 
            _hooks.Clear();
        }
 
        public static void UninstallByTag(string tag)
        {
            var list = _hooks.Values.ToList();
            foreach (var hook in list)
            {
                if(hook.tag == tag)
                    hook.Uninstall();
            }
        }
 
        public static List<MethodHook> GetAllHooks()
        {
            return _hooks.Values.ToList();
        }
    }
 
}