~ruther/NosSmooth.Local

ref: bc07ee96c7a5886761d7b0ed796a92ec9214711b NosSmooth.Local/src/Core/NosSmooth.LocalBinding/Structs/NtClient.cs -rw-r--r-- 2.3 KiB
bc07ee96 — Rutherther fix(binding): fix periodic hook wrapper function to return empty 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
//
//  NtClient.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.

using NosSmooth.LocalBinding.Errors;
using NosSmooth.LocalBinding.Extensions;
using NosSmooth.LocalBinding.Options;
using Reloaded.Memory.Sources;
using Remora.Results;

namespace NosSmooth.LocalBinding.Structs;

/// <summary>
/// A NosTale client base object.
/// </summary>
public class NtClient : NostaleObject
{
    /// <summary>
    /// Create <see cref="NtClient"/> instance.
    /// </summary>
    /// <param name="nosBrowserManager">The NosTale process browser.</param>
    /// <param name="options">The options.</param>
    /// <returns>The player manager or an error.</returns>
    public static Result<NtClient> Create(NosBrowserManager nosBrowserManager, NtClientOptions options)
    {
        var networkObjectAddress = nosBrowserManager.Scanner.FindPattern(options.NtClientPattern);
        if (!networkObjectAddress.Found)
        {
            return new BindingNotFoundError(options.NtClientPattern, "NtClient");
        }

        if (nosBrowserManager.Process.MainModule is null)
        {
            return new NotFoundError("Cannot find the main module of the target process.");
        }

        var staticAddress = (nuint)(nosBrowserManager.Process.MainModule.BaseAddress + networkObjectAddress.Offset);
        return new NtClient(nosBrowserManager.Memory, staticAddress, options.NtClientOffsets);
    }

    private readonly IMemory _memory;
    private readonly int _staticNtClientAddress;
    private readonly int[] _ntClientOffsets;

    private NtClient(IMemory memory, nuint staticNtClientAddress, int[] ntClientOffsets)
        : base(memory, nuint.Zero)
    {
        _memory = memory;
        _staticNtClientAddress = (int)staticNtClientAddress;
        _ntClientOffsets = ntClientOffsets;
    }

    /// <summary>
    /// Gets the address to the player manager.
    /// </summary>
    public override nuint Address => _memory.FollowStaticAddressOffsets
        (_staticNtClientAddress, _ntClientOffsets);

    /// <summary>
    /// Gets the encryption key used for world encryption.
    /// </summary>
    public int EncryptionKey
    {
        get
        {
            _memory.SafeRead(Address + 0x48, out int encryptionKey);
            return encryptionKey;
        }
    }
}
Do not follow this link