~ruther/NosSmooth.Local

ref: ce0260d5b61a99ecbbd13177283632c4a7a2e28c NosSmooth.Local/src/Core/NosSmooth.LocalBinding/Hooks/HookOptionsBuilder.cs -rw-r--r-- 2.0 KiB
ce0260d5 — František Boháček feat: update to managed and raw client 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
//
//  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.Hooks;

/// <summary>
/// Builder for <see cref="HookOptions"/>.
/// </summary>
/// <typeparam name="T">The type of hook options.</typeparam>
public class HookOptionsBuilder<T>
{
    private string _name;
    private bool _hook;
    private string _pattern;
    private int _offset;

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

    /// <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<T> 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<T> 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<T> Offset(int offset)
    {
        _offset = offset;
        return this;
    }

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