M Local/NosSmooth.LocalClient/LocalClientOptions.cs => Local/NosSmooth.LocalClient/LocalClientOptions.cs +26 -0
@@ 4,6 4,8 @@
// 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.Core.Commands;
+
namespace NosSmooth.LocalClient;
/// <summary>
@@ 15,4 17,28 @@ public class LocalClientOptions
/// Gets or sets whether the interception of packets should be allowed.
/// </summary>
public bool AllowIntercept { get; set; }
+
+ /// <summary>
+ /// Hook the packet sent method.
+ /// </summary>
+ /// <remarks>
+ /// Packet handlers and interceptors won't be called for sent packets.
+ /// </remarks>
+ public bool HookPacketSend { get; set; } = true;
+
+ /// <summary>
+ /// Hook the packet received method.
+ /// </summary>
+ /// <remarks>
+ /// Packet handlers and interceptors won't be called for received packets.
+ /// </remarks>
+ public bool HookPacketReceive { get; set; } = true;
+
+ /// <summary>
+ /// Whether to hook Character.Walk method. True by default.
+ /// </summary>
+ /// <remarks>
+ /// If set to false, <see cref="WalkCommand.CancelOnUserMove"/> won't take any effect.
+ /// </remarks>
+ public bool HookCharacterWalk { get; set; } = true;
}=
\ No newline at end of file
M Local/NosSmooth.LocalClient/NostaleLocalClient.cs => Local/NosSmooth.LocalClient/NostaleLocalClient.cs +17 -2
@@ 68,12 68,26 @@ public class NostaleLocalClient : BaseNostaleClient
/// <inheritdoc />
public override async Task<Result> RunAsync(CancellationToken stopRequested = default)
{
+ _stopRequested = stopRequested;
_logger.LogInformation("Starting local client");
NetworkCallback receiveCallback = ReceiveCallback;
NetworkCallback sendCallback = SendCallback;
- _client.GetNetwork().SetReceiveCallback(receiveCallback);
- _client.GetNetwork().SetSendCallback(sendCallback);
+ if (_options.HookPacketReceive)
+ {
+ _client.GetNetwork().SetReceiveCallback(receiveCallback);
+ }
+
+ if (_options.HookPacketSend)
+ {
+ _client.GetNetwork().SetSendCallback(sendCallback);
+ }
+
+ if (_options.HookCharacterWalk)
+ {
+ _hookManager.HookCharacterWalk();
+ }
+
_logger.LogInformation("Packet methods hooked successfully");
try
@@ 82,6 96,7 @@ public class NostaleLocalClient : BaseNostaleClient
}
catch
{
+ // ignored
}
_client.ResetHooks();