From 43fc69eb0fe846ce15d97cff16cc6e2e2821d232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Thu, 23 Dec 2021 16:08:43 +0100 Subject: [PATCH] feat: add hooking options to determine if the library should hook --- .../LocalClientOptions.cs | 26 +++++++++++++++++++ .../NostaleLocalClient.cs | 19 ++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Local/NosSmooth.LocalClient/LocalClientOptions.cs b/Local/NosSmooth.LocalClient/LocalClientOptions.cs index ba20eb4..5294ce8 100644 --- a/Local/NosSmooth.LocalClient/LocalClientOptions.cs +++ b/Local/NosSmooth.LocalClient/LocalClientOptions.cs @@ -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; /// @@ -15,4 +17,28 @@ public class LocalClientOptions /// Gets or sets whether the interception of packets should be allowed. /// public bool AllowIntercept { get; set; } + + /// + /// Hook the packet sent method. + /// + /// + /// Packet handlers and interceptors won't be called for sent packets. + /// + public bool HookPacketSend { get; set; } = true; + + /// + /// Hook the packet received method. + /// + /// + /// Packet handlers and interceptors won't be called for received packets. + /// + public bool HookPacketReceive { get; set; } = true; + + /// + /// Whether to hook Character.Walk method. True by default. + /// + /// + /// If set to false, won't take any effect. + /// + public bool HookCharacterWalk { get; set; } = true; } \ No newline at end of file diff --git a/Local/NosSmooth.LocalClient/NostaleLocalClient.cs b/Local/NosSmooth.LocalClient/NostaleLocalClient.cs index 89f5b91..62693fe 100644 --- a/Local/NosSmooth.LocalClient/NostaleLocalClient.cs +++ b/Local/NosSmooth.LocalClient/NostaleLocalClient.cs @@ -68,12 +68,26 @@ public class NostaleLocalClient : BaseNostaleClient /// public override async Task 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(); -- 2.48.1