~ruther/NosSmooth.Local

3fef05595453b3cf3058582e146990509b1ec5ce — Rutherther 2 years ago 23b5f39
feat(samples): implement support for optional modules and hooks
M src/Samples/External/ExternalBrowser/Program.cs => src/Samples/External/ExternalBrowser/Program.cs +3 -3
@@ 55,17 55,17 @@ public class Program
                    Console.Error.WriteLine(initializationResult.ToFullString());
                }

                var length = externalBrowser.PetManagerList.Length;
                var length = externalBrowser.PetManagerList.Get().Length;
                Console.WriteLine(length);

                if (!externalBrowser.IsInGame)
                if (!externalBrowser.IsInGame.Get())
                {
                    Console.Error.WriteLine("The player is not in game, cannot get the name of the player.");
                    continue;
                }

                Console.WriteLine
                    ($"Player in process {process.Id} is named {externalBrowser.PlayerManager.Player.Name}");
                    ($"Player in process {process.Id} is named {externalBrowser.PlayerManager.Get().Player.Name}");
            }
        }
    }

M src/Samples/HighLevel/SimplePiiBot/Commands/EntityCommands.cs => src/Samples/HighLevel/SimplePiiBot/Commands/EntityCommands.cs +13 -16
@@ 107,18 107,17 @@ public class EntityCommands : CommandGroup
    public async Task<Result> HandleFocusAsync(int entityId)
    {
        var entityResult = _sceneManager.FindEntity(entityId);
        if (!entityResult.IsSuccess)
        if (!entityResult.IsDefined(out var entity))
        {
            return Result.FromError(entityResult);
        }

        return await _synchronizer.SynchronizeAsync
        (
            () =>
            {
                _hookManager.EntityFocus.WrapperFunction(entityResult.Entity);
                return Result.FromSuccess();
            },
            () => _hookManager.EntityFocus.MapResult
            (
                focus => focus.WrapperFunction.MapResult(wrapper => wrapper(entity))
            ),
            CancellationToken
        );
    }


@@ 139,11 138,10 @@ public class EntityCommands : CommandGroup

        return await _synchronizer.SynchronizeAsync
        (
            () =>
            {
                _hookManager.EntityFollow.WrapperFunction(entity);
                return Result.FromSuccess();
            },
            () => _hookManager.EntityFollow.MapResult
            (
                follow => follow.WrapperFunction.MapResult(wrapper => wrapper(entity))
            ),
            CancellationToken
        );
    }


@@ 157,11 155,10 @@ public class EntityCommands : CommandGroup
    {
        return await _synchronizer.SynchronizeAsync
        (
            () =>
            {
                _hookManager.EntityUnfollow.WrapperFunction();
                return Result.FromSuccess();
            },
            () => _hookManager.EntityUnfollow.MapResult
            (
                unfollow => unfollow.WrapperFunction.MapResult(wrapper => wrapper())
            ),
            CancellationToken
        );
    }

M src/Samples/HighLevel/SimplePiiBot/HostedService.cs => src/Samples/HighLevel/SimplePiiBot/HostedService.cs +10 -0
@@ 11,6 11,7 @@ using NosSmooth.Core.Client;
using NosSmooth.Core.Extensions;
using NosSmooth.Data.NOSFiles;
using NosSmooth.LocalBinding;
using NosSmooth.LocalBinding.Hooks;
using NosSmooth.PacketSerializer.Extensions;
using NosSmooth.PacketSerializer.Packets;
using OneOf.Types;


@@ 78,6 79,15 @@ public class HostedService : BackgroundService
        if (!bindingResult.IsSuccess)
        {
            _logger.LogResultError(bindingResult);
        }

        if (!_bindingManager.IsModulePresent<IPeriodicHook>() || !_bindingManager.IsModulePresent<IPacketSendHook>()
            || !_bindingManager.IsModulePresent<IPacketReceiveHook>())
        {
            _logger.LogError
            (
                "At least one of: periodic, packet receive, packet send has not been loaded correctly, the bot may not be used at all. Aborting"
            );
            return;
        }


M src/Samples/LowLevel/InterceptNameChanger/NameChanger.cs => src/Samples/LowLevel/InterceptNameChanger/NameChanger.cs +11 -0
@@ 11,6 11,7 @@ using NosSmooth.Core.Client;
using NosSmooth.Core.Extensions;
using NosSmooth.Extensions.SharedBinding.Extensions;
using NosSmooth.LocalBinding;
using NosSmooth.LocalBinding.Hooks;
using NosSmooth.LocalClient;
using NosSmooth.LocalClient.Extensions;
using NosSmooth.Packets.Enums;


@@ 63,6 64,16 @@ namespace InterceptNameChanger
                logger.LogResultError(initializeResult);
            }

            if (!bindingManager.IsModulePresent<IPeriodicHook>() || !bindingManager.IsModulePresent<IPacketSendHook>()
                || !bindingManager.IsModulePresent<IPacketReceiveHook>())
            {
                logger.LogError
                (
                    "At least one of: periodic, packet receive, packet send has not been loaded correctly, the bot may not be used at all. Aborting"
                );
                return;
            }
            
            var packetTypesRepository = provider.GetRequiredService<IPacketTypesRepository>();
            var packetAddResult = packetTypesRepository.AddDefaultPackets();
            if (!packetAddResult.IsSuccess)

M src/Samples/LowLevel/SimpleChat/SimpleChat.cs => src/Samples/LowLevel/SimpleChat/SimpleChat.cs +11 -0
@@ 10,6 10,7 @@ using NosSmooth.Core.Client;
using NosSmooth.Core.Extensions;
using NosSmooth.Extensions.SharedBinding.Extensions;
using NosSmooth.LocalBinding;
using NosSmooth.LocalBinding.Hooks;
using NosSmooth.LocalClient.Extensions;
using NosSmooth.Packets.Enums;
using NosSmooth.Packets.Enums.Chat;


@@ 57,6 58,16 @@ public class SimpleChat
            logger.LogError($"Could not initialize NosBindingManager.");
            logger.LogResultError(initializeResult);
        }
        
        if (!bindingManager.IsModulePresent<IPeriodicHook>() || !bindingManager.IsModulePresent<IPacketSendHook>()
            || !bindingManager.IsModulePresent<IPacketReceiveHook>())
        {
            logger.LogError
            (
                "At least one of: periodic, packet receive, packet send has not been loaded correctly, the bot may not be used at all. Aborting"
            );
            return;
        }

        var packetTypesRepository = provider.GetRequiredService<IPacketTypesRepository>();
        var packetAddResult = packetTypesRepository.AddDefaultPackets();

M src/Samples/LowLevel/WalkCommands/Startup.cs => src/Samples/LowLevel/WalkCommands/Startup.cs +11 -0
@@ 16,6 16,7 @@ using NosSmooth.Extensions.Pathfinding.Extensions;
using NosSmooth.Extensions.SharedBinding.Extensions;
using NosSmooth.LocalBinding;
using NosSmooth.LocalBinding.Extensions;
using NosSmooth.LocalBinding.Hooks;
using NosSmooth.LocalClient;
using NosSmooth.LocalClient.Extensions;
using NosSmooth.PacketSerializer.Extensions;


@@ 82,6 83,16 @@ public class Startup
            logger.LogError($"Could not initialize NosBindingManager.");
            logger.LogResultError(initializeResult);
        }
        
        if (!bindingManager.IsModulePresent<IPeriodicHook>() || !bindingManager.IsModulePresent<IPacketSendHook>()
            || !bindingManager.IsModulePresent<IPacketReceiveHook>())
        {
            logger.LogError
            (
                "At least one of: periodic, packet receive, packet send has not been loaded correctly, the bot may not be used at all. Aborting"
            );
            return;
        }

        var packetTypesRepository = provider.GetRequiredService<IPacketTypesRepository>();
        var packetAddResult = packetTypesRepository.AddDefaultPackets();

Do not follow this link