~ruther/NosSmooth.Local

ref: bbad5288a9a78ffcd23ecf2cc5650432180be327 NosSmooth.Local/src/Core/NosSmooth.LocalBinding/HookOptionsBuilder.cs -rw-r--r-- 2.3 KiB
bbad5288 — Rutherther feat(binding): add hook config builder for configuring what hooks to enable 2 years ago
                                                                                
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
75
76
77
78
79
80
81
82
83
//
//  HookOptionsBuilder.cs
//
//  Copyright (c) František Boháček. All rights reserved.
//  Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace NosSmooth.LocalBinding;

/// <summary>
/// Builder for <see cref="HookOptions"/>.
/// </summary>
public class HookOptionsBuilder
{
    private bool _hook;
    private string _pattern;
    private int _offset;

    /// <summary>
    /// Initializes a new instance of the <see cref="HookOptionsBuilder"/> class.
    /// </summary>
    /// <param name="options">The options.</param>
    internal HookOptionsBuilder(HookOptions options)
    {
        _hook = options.Hook;
        _pattern = options.MemoryPattern;
        _offset = options.Offset;
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="HookOptionsBuilder"/> class.
    /// </summary>
    /// <param name="hook">Whether to hook the function.</param>
    /// <param name="pattern">The default pattern.</param>
    /// <param name="offset">The default offset.</param>
    internal HookOptionsBuilder(bool hook, string pattern, int offset)
    {
        _offset = offset;
        _pattern = pattern;
        _hook = hook;
    }

    /// <summary>
    /// Configure whether to hook this function.
    /// Default true.
    /// </summary>
    /// <param name="hook">Whether to hook the function.</param>
    /// <returns>This builder.</returns>
    public HookOptionsBuilder Hook(bool hook = true)
    {
        _hook = hook;
        return this;
    }

    /// <summary>
    /// Configure the memory pattern.
    /// Use ?? for any bytes.
    /// </summary>
    /// <param name="pattern">The memory pattern.</param>
    /// <returns>This builder.</returns>
    public HookOptionsBuilder MemoryPattern(string pattern)
    {
        _pattern = pattern;
        return this;
    }

    /// <summary>
    /// Configure the offset from the pattern.
    /// </summary>
    /// <param name="offset">The offset.</param>
    /// <returns>This builder.</returns>
    public HookOptionsBuilder Offset(int offset)
    {
        _offset = offset;
        return this;
    }

    /// <summary>
    /// Create hook options from this builder.
    /// </summary>
    /// <returns>The options.</returns>
    internal HookOptions Build()
        => new HookOptions(_hook, _pattern, _offset);
}
Do not follow this link