Exemple #1
0
        public static Action <Task, string> DoSendCommand(MiNetClient client)
        {
            Action <Task, string> doUseItem = (t, command) =>
            {
                McpeCommandStep commandStep = McpeCommandStep.CreateObject();
                commandStep.commandName     = "help";
                commandStep.commandOverload = "byPage";
                commandStep.unknown1        = 0;
                commandStep.currentStep     = 0;
                commandStep.isOutput        = false;
                commandStep.clientId        = -1;
                //commandStep.commandJson = @"{}";
                //commandStep.unkown6 = @"{}";
                commandStep.commandInputJson  = "null\n";
                commandStep.commandOutputJson = "null\n";
                commandStep.unknown7          = 0;
                commandStep.unknown8          = 0;
                commandStep.entityIdSelf      = client.NetworkEntityId;
                Log.Error($"Entity ID used={client.EntityId}\n{Package.HexDump(commandStep.Encode())}");

                client.SendPackage(commandStep);
            };

            return(doUseItem);
        }
Exemple #2
0
        public static Action <Task, string> DoSendCommand(MiNetClient client)
        {
            Action <Task, string> doUseItem = (t, command) =>
            {
                McpeCommandRequest commandStep = McpeCommandRequest.CreateObject();
                commandStep.commandName     = "fill";
                commandStep.commandOverload = "replace";
                commandStep.unknown1        = 0;
                commandStep.currentStep     = 0;
                commandStep.isOutput        = false;
                commandStep.clientId        = client.ClientId;
                //commandStep.commandInputJson = "{\n   \"tileName\" : \"dirt\",\n   \"from\" : {\n      \"x\" : 0,\n      \"xrelative\" : false,\n      \"y\" : 10,\n      \"yrelative\" : false,\n      \"z\" : 0,\n      \"zrelative\" : false\n   },\n   \"to\" : {\n      \"x\" : 10,\n      \"xrelative\" : false,\n      \"y\" : 10,\n      \"yrelative\" : false,\n      \"z\" : 10,\n      \"zrelative\" : false\n   }\n}\n";
                commandStep.commandInputJson = "{\n   \"from\" : {\n      \"x\" : 0,\n      \"xrelative\" : false,\n      \"y\" : 10,\n      \"yrelative\" : false,\n      \"z\" : 0,\n      \"zrelative\" : false\n   },\n   \"tileName\" : \"dirt\",\n   \"to\" : {\n      \"x\" : 10,\n      \"xrelative\" : false,\n      \"y\" : 10,\n      \"yrelative\" : false,\n      \"z\" : 10,\n      \"zrelative\" : false\n   }\n}\n";
                //   "commandInputJson": "{\n   \"from\" : {\n      \"x\" : 0,\n      \"xrelative\" : false,\n      \"y\" : 10,\n      \"yrelative\" : false,\n      \"z\" : 0,\n      \"zrelative\" : false\n   },\n   \"tileName\" : \"dirt\",\n   \"to\" : {\n      \"x\" : 10,\n      \"xrelative\" : false,\n      \"y\" : 10,\n      \"yrelative\" : false,\n      \"z\" : 10,\n      \"zrelative\" : false\n   }\n}\n",

                //commandStep.commandInputJson = "null\n";
                commandStep.commandOutputJson = "null\n";
                commandStep.unknown7          = 0;
                commandStep.unknown8          = 0;
                commandStep.entityIdSelf      = client.NetworkEntityId;
                //Log.Error($"Entity ID used={commandStep.entityIdSelf}\n{Package.HexDump(commandStep.Encode())}");
                client.SendPackage(commandStep);
            };

            return(doUseItem);
        }
Exemple #3
0
        public static Action <Task, int, Item, int> DoContainerSetSlot(MiNetClient client)
        {
            Action <Task, int, Item, int> doMobEquipmentTask = (t, windowId, item, selectedSlot) =>
            {
                McpeContainerSetSlot message = new McpeContainerSetSlot();
                message.windowId = (byte)windowId;
                message.slot     = selectedSlot;
                message.item     = item;
                client.SendPackage(message);
            };

            return(doMobEquipmentTask);
        }
Exemple #4
0
        public static Action <Task, Item, int> DoMobEquipment(MiNetClient client)
        {
            Action <Task, Item, int> doMobEquipmentTask = (t, item, selectedSlot) =>
            {
                McpeMobEquipment message = new McpeMobEquipment();
                message.runtimeEntityId = client.EntityId;
                message.item            = item;
                message.selectedSlot    = (byte)selectedSlot;
                message.slot            = (byte)(selectedSlot + 9);
                client.SendPackage(message);
            };

            return(doMobEquipmentTask);
        }
Exemple #5
0
        public static Action <Task, Item, BlockCoordinates> DoUseItem(MiNetClient client)
        {
            Action <Task, Item, BlockCoordinates> doUseItem = (t, item, coords) =>
            {
                McpeUseItem message = new McpeUseItem();
                message.blockcoordinates = coords /* - new BlockCoordinates(0, 1, 0)*/;
                message.face             = 4;
                message.facecoordinates  = new Vector3(0.1f, 0.1f, 0.1f);
                message.playerposition   = client.CurrentLocation.ToVector3();
                message.item             = item;
                client.SendPackage(message);
            };

            return(doUseItem);
        }
Exemple #6
0
        public static Action <Task, PlayerLocation> DoMoveTo(MiNetClient client)
        {
            Action <Task, PlayerLocation> doMoveTo = (t, loc) =>
            {
                Vector3 originalPosition = client.CurrentLocation.ToVector3();
                Vector3 targetPosition   = loc.ToVector3();

                PlayerLocation lookAtPos = LookAt(originalPosition + new Vector3(0, 1.62f, 0), targetPosition);

                {
                    // First just rotate towards target pos
                    McpeMovePlayer movePlayerPacket = McpeMovePlayer.CreateObject();
                    movePlayerPacket.runtimeEntityId = client.EntityId;
                    movePlayerPacket.x       = client.CurrentLocation.X;
                    movePlayerPacket.y       = client.CurrentLocation.Y;
                    movePlayerPacket.z       = client.CurrentLocation.Z;
                    movePlayerPacket.yaw     = lookAtPos.Yaw;
                    movePlayerPacket.pitch   = lookAtPos.Pitch;
                    movePlayerPacket.headYaw = lookAtPos.HeadYaw;
                }
                float lenght = Math.Abs((originalPosition - targetPosition).Length());

                float stepLen = 0.5f;
                float weight;

                while (true)
                {
                    if (Math.Abs((targetPosition - client.CurrentLocation.ToVector3()).Length()) > stepLen)
                    {
                        float lenLeft = Math.Abs((client.CurrentLocation.ToVector3() - targetPosition).Length());
                        weight = Math.Abs((float)((lenLeft - stepLen) / lenght));

                        client.CurrentLocation = new PlayerLocation(Vector3.Lerp(originalPosition, targetPosition, 1 - weight));

                        McpeMovePlayer movePlayerPacket = McpeMovePlayer.CreateObject();
                        movePlayerPacket.runtimeEntityId = client.EntityId;
                        movePlayerPacket.x       = client.CurrentLocation.X;
                        movePlayerPacket.y       = client.CurrentLocation.Y;
                        movePlayerPacket.z       = client.CurrentLocation.Z;
                        movePlayerPacket.yaw     = lookAtPos.Yaw;
                        movePlayerPacket.pitch   = lookAtPos.Pitch;
                        movePlayerPacket.headYaw = lookAtPos.HeadYaw;

                        client.SendPackage(movePlayerPacket);

                        Thread.Sleep(50);
                        continue;
                    }
                    {
                        client.CurrentLocation = new PlayerLocation(targetPosition);

                        McpeMovePlayer movePlayerPacket = McpeMovePlayer.CreateObject();
                        movePlayerPacket.runtimeEntityId = client.EntityId;
                        movePlayerPacket.x       = client.CurrentLocation.X;
                        movePlayerPacket.y       = client.CurrentLocation.Y;
                        movePlayerPacket.z       = client.CurrentLocation.Z;
                        movePlayerPacket.yaw     = lookAtPos.Yaw;
                        movePlayerPacket.pitch   = lookAtPos.Pitch;
                        movePlayerPacket.headYaw = lookAtPos.HeadYaw;

                        client.SendPackage(movePlayerPacket);
                    }
                    break;
                }
            };

            return(doMoveTo);
        }
Exemple #7
0
        protected override void OnMessage(MessageEventArgs e)
        {
            try
            {
                var json = JObject.Parse(e.Data);
                if ((string)json["action"] == "send_packet")
                {
                    if (Client == null || !Client.HaveServer)
                    {
                        return;
                    }
                    var pk     = (string)json["pk"];
                    var packet = json["packet"];
                    switch (pk)
                    {
                    case "interact":
                        var interact = McpeInteract.CreateObject();
                        interact.actionId = (byte)packet["action"];
                        interact.targetRuntimeEntityId = (long)packet["entityId"];
                        Client.SendPackage(interact);
                        break;

                    case "move":
                        Client.CurrentLocation = new PlayerLocation((float)packet["x"], (float)packet["y"], (float)packet["z"]);
                        Console.WriteLine("move to " + Client.CurrentLocation);
                        Client.SendMcpeMovePlayer();
                        break;
                    }
                }
                else if ((string)json["action"] == "command")
                {
                    var args = ((string)json["message"]).Split(' ');
                    switch (args[0].ToLower())
                    {
                    case "chat":
                        Client.SendChat(string.Join(" ", args.Skip(1)));
                        break;

                    case "disconnect":
                        if (Client != null)
                        {
                            Client.SendDisconnectionNotification();
                            CommandResponse("Disconnected");
                        }
                        else
                        {
                            CommandResponse("Not connected");
                        }
                        break;

                    case "connect":
                        IPAddress ip;
                        if (args.Length <= 1)
                        {
                            ip = IPAddress.Loopback;
                        }
                        else
                        {
                            var addresses = Dns.GetHostEntry(args[1]).AddressList;
                            if (addresses.Length > 0)
                            {
                                ip = addresses[0];
                            }
                            else if (IPAddress.TryParse(args[1], out ip))
                            {
                                CommandResponse("Bad ip: " + args[1]);
                                return;
                            }
                        }

                        short port;
                        if (args.Length <= 2)
                        {
                            port = 19132;
                        }
                        else
                        {
                            if (!short.TryParse(args[2], out port))
                            {
                                CommandResponse("Bad port: " + args[2]);
                                return;
                            }
                        }

                        string username;
                        if (args.Length <= 3)
                        {
                            username = "******";
                        }
                        else
                        {
                            username = args[3];
                        }

                        CommandResponse("Connecting to " + ip + ":" + port);
                        var endpoint = new IPEndPoint(ip, port);
                        Connect(endpoint, username);
                        break;

                    default:
                        Send("Unknown command!");
                        break;
                    }
                }
                else if ((string)json["action"] == "chat")
                {
                    Client.SendChat((string)json["message"]);
                }
            } catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }