Rutherther / NosSmooth

Nostale bot library written in C#. May describe the current state of the game/character from packets. Multiple sources available for capturing the packets from running game.
MIT License
6 stars 3 forks source link

Sending PtctlPacket does nothing #70

Closed plsfixrito closed 1 year ago

plsfixrito commented 1 year ago

Code example

        public async Task RunAsync()
        {
            var client = Service.GetRequiredService<ManagedNostaleClient>();
            if (client is null) return;

            var game = Service.GetRequiredService<Game>();
            if (game is null) return;

            var character = game.Character;
            if (character is null) return;

            foreach (var entity in game.CurrentMap.Entities.GetEntities())
            {
                if (entity.Type != EntityType.Npc) continue;

                var npc = entity as Npc;
                if (npc is null) continue;

                if (npc.OwnerId != character.Id) continue;

                var position = character.Position;
                if (position is null) continue;

                var movePkt = new PtctlSubPacket(npc.Id, position.Value.X, position.Value.Y);
                var fullFpkt = new PtctlPacket((short)game.CurrentMap.Id, 1, new List<PtctlSubPacket>() { movePkt });
                await client.SendPacketAsync(fullFpkt);
                break;
            }
        }
Rutherther commented 1 year ago

Please check the result returned from SendPacketAsync, it's possible it's an error and that could tell you more information. Have you called AddDefaultPackets on IPacketTypesRepository?

Rutherther commented 1 year ago

Also I am not sure whether something should happen, I have never tried sending Ptctl packet directly, doesn't that work similar to walk? ie. you will not see the change on your client. I have seen your issue on the Local repository so it looks like you know about PetWalkCommand, use that. PetWalkCommand calls functions from memory directly and is similar to clicking on the map.

plsfixrito commented 1 year ago

This packet is sent when moving pets from client to server. It should move the pet or partner when called.

I already added these services


            BindingManager = Service.GetRequiredService<NosBindingManager>();
            var logger = Service.GetRequiredService<ILogger<Sandbox>>();
            var initializeResult = BindingManager.Initialize();
            if (!initializeResult.IsSuccess)
            {
                logger.LogError($"Could not initialize NosBindingManager.");
                logger.LogResultError(initializeResult);
            }

            var packetTypesRepository = Service.GetRequiredService<IPacketTypesRepository>();
            var packetAddResult = packetTypesRepository.AddDefaultPackets();
            if (!packetAddResult.IsSuccess)
            {
                logger.LogError("Could not initialize default packet serializers correctly");
                logger.LogResultError(packetAddResult);
            }

            DataService = Service.GetRequiredService<NostaleDataFilesManager>();
            var dataResult = DataService.Initialize();
            if (!dataResult.IsSuccess)
            {
                logger.LogError("Could not initialize the nostale data files");
                logger.LogResultError(dataResult);
            }
plsfixrito commented 1 year ago

Please check the result returned from SendPacketAsync, it's possible it's an error and that could tell you more information. Have you called AddDefaultPackets on IPacketTypesRepository?

SendPacketAsync returns success when sending the packet. Also after checking the packet again it seems to have missing arguments. I will add a pull request correcting the packet.

Rutherther commented 1 year ago

Do you mean that it does nothing from point of view of the client sending it? I have tried it with packet logger and it indeed does nothing, but that is because the client just does not handle that. From view of others the mates move. To see the mates move, PetWalkCommand has to be used.

Rutherther commented 1 year ago

If you really needed this, one thing that comes to mind is, you could teleport the mates for the client to the destination by receiving TpPacket, but that is not gonna show you animation of them moving and the timing will be wrong for your client.

Also be aware that implementing walking through this packet yourself may be tricky. At least if you want the packet to work the same as it does from the client. If you walk somewhere with the pets with client, ptctl is sent every ~2 blocks (that number depends on the speed), not directly to the target position. The client can handle all this itself using PetWalkCommand.