예제 #1
0
 void WritePacket()
 {
     data[0] = Opcode.LevelDataChunk;
     NetUtils.WriteU16((ushort)index, data, 1);
     data[1027] = (byte)(100 * (float)position / length);
     p.Send(data);
     index = 0;
 }
예제 #2
0
 public static byte[] GetPositionPacket(PlayerBot bot)
 {
     // TODO: not sure why bots only work with absolute packets
     byte[] buffer = new byte[10];
     buffer[0] = Opcode.EntityTeleport;
     buffer[1] = bot.id;
     NetUtils.WriteU16(bot.pos[0], buffer, 2);
     NetUtils.WriteU16(bot.pos[1], buffer, 4);
     NetUtils.WriteU16(bot.pos[2], buffer, 6);
     buffer[8] = bot.rot[0];
     buffer[9] = bot.rot[1];
     return(buffer);
 }
예제 #3
0
        public void SendPos(byte id, ushort x, ushort y, ushort z, byte rotx, byte roty)
        {
            if (x < 0)
            {
                x = 32;
            }
            if (y < 0)
            {
                y = 32;
            }
            if (z < 0)
            {
                z = 32;
            }
            if (x > level.Width * 32)
            {
                x = (ushort)(level.Width * 32 - 32);
            }
            if (z > level.Length * 32)
            {
                z = (ushort)(level.Length * 32 - 32);
            }
            if (x > 32767)
            {
                x = 32730;
            }
            if (y > 32767)
            {
                y = 32730;
            }
            if (z > 32767)
            {
                z = 32730;
            }

            pos[0] = x; pos[1] = y; pos[2] = z;
            rot[0] = rotx; rot[1] = roty;

            byte[] buffer = new byte[10];
            buffer[0] = Opcode.EntityTeleport;
            buffer[1] = id;
            NetUtils.WriteU16(x, buffer, 2);
            NetUtils.WriteU16(y, buffer, 4);
            NetUtils.WriteU16(z, buffer, 6);
            buffer[8] = rotx;
            buffer[9] = roty;
            SendRaw(buffer);
        }
예제 #4
0
        public void SendSpawn(byte id, string name, ushort x, ushort y, ushort z, byte rotx, byte roty)
        {
            byte[] buffer = new byte[74];
            buffer[0] = Opcode.AddEntity;
            buffer[1] = id;
            NetUtils.WriteAscii(name.TrimEnd('+'), buffer, 2);
            NetUtils.WriteU16(x, buffer, 66);
            NetUtils.WriteU16(y, buffer, 68);
            NetUtils.WriteU16(z, buffer, 70);
            buffer[72] = rotx;
            buffer[73] = roty;
            SendRaw(buffer);

            if (hasChangeModel)
            {
                UpdateModels();
            }
        }
예제 #5
0
        public void SendBlockchange(ushort x, ushort y, ushort z, BlockID block)
        {
            //if (x < 0 || y < 0 || z < 0) return;
            if (x >= level.Width || y >= level.Height || z >= level.Length)
            {
                return;
            }

            byte[] buffer = new byte[hasExtBlocks ? 9 : 8];
            buffer[0] = Opcode.SetBlock;
            NetUtils.WriteU16(x, buffer, 1);
            NetUtils.WriteU16(y, buffer, 3);
            NetUtils.WriteU16(z, buffer, 5);

            BlockID raw = ConvertBlock(block);

            NetUtils.WriteBlock(raw, buffer, 7, hasExtBlocks);
            Socket.Send(buffer, SendFlags.LowPriority);
        }
예제 #6
0
        public void SendExtAddEntity2(byte id, string skinName, string displayName, ushort x, ushort y, ushort z, byte rotx, byte roty)
        {
            byte[] buffer = new byte[138];
            buffer[0] = Opcode.CpeExtAddEntity2;
            buffer[1] = id;
            NetUtils.WriteAscii(displayName.TrimEnd('+'), buffer, 2);
            NetUtils.WriteAscii(skinName.TrimEnd('+'), buffer, 66);
            NetUtils.WriteU16(x, buffer, 130);
            NetUtils.WriteU16(y, buffer, 132);
            NetUtils.WriteU16(z, buffer, 134);
            buffer[136] = rotx;
            buffer[137] = roty;
            SendRaw(buffer);

            if (hasChangeModel)
            {
                UpdateModels();
            }
        }
예제 #7
0
        public void SendBlockchange(ushort x, ushort y, ushort z, ExtBlock block)
        {
            //if (x < 0 || y < 0 || z < 0) return;
            if (x >= level.Width || y >= level.Height || z >= level.Length)
            {
                return;
            }

            byte[] buffer = new byte[8];
            buffer[0] = Opcode.SetBlock;
            NetUtils.WriteU16(x, buffer, 1);
            NetUtils.WriteU16(y, buffer, 3);
            NetUtils.WriteU16(z, buffer, 5);

            byte raw;

            if (block.BlockID == Block.custom_block)
            {
                raw = hasBlockDefs ? block.ExtID : level.RawFallback(block.ExtID);
            }
            else
            {
                raw = Block.Convert(block.BlockID);
            }
            if (!hasCustomBlocks)
            {
                raw = Block.ConvertCPE(raw);                   // client doesn't support CPE
            }
            // Custom block replaced a core block
            if (!hasBlockDefs && raw < Block.CpeCount)
            {
                BlockDefinition def = level.CustomBlockDefs[raw];
                if (def != null)
                {
                    raw = def.FallBack;
                }
            }

            buffer[7] = raw;
            Socket.SendLowPriority(buffer);
        }
예제 #8
0
        public static byte[] MakeSelection(byte id, string label, Vec3U16 p1, Vec3U16 p2,
                                           short r, short g, short b, short opacity)
        {
            byte[] buffer = new byte[86];
            buffer[0] = Opcode.CpeMakeSelection;
            buffer[1] = id;
            NetUtils.WriteAscii(label, buffer, 2);

            NetUtils.WriteU16(p1.X, buffer, 66);
            NetUtils.WriteU16(p1.Y, buffer, 68);
            NetUtils.WriteU16(p1.Z, buffer, 70);
            NetUtils.WriteU16(p2.X, buffer, 72);
            NetUtils.WriteU16(p2.Y, buffer, 74);
            NetUtils.WriteU16(p2.Z, buffer, 76);

            NetUtils.WriteI16(r, buffer, 78);
            NetUtils.WriteI16(g, buffer, 80);
            NetUtils.WriteI16(b, buffer, 82);
            NetUtils.WriteI16(opacity, buffer, 84);
            return(buffer);
        }
예제 #9
0
        /// <summary> Sends a packet indicating an entity was spawned in the current map
        /// at the given absolute position + coordinates </summary>
        public void SendSpawn(byte id, string name, ushort x, ushort y, ushort z, byte rotx, byte roty)
        {
            // NOTE: Fix for standard clients
            if (id == Entities.SelfID)
            {
                y -= 22;
            }

            byte[] buffer = new byte[74];
            buffer[0] = Opcode.AddEntity;
            buffer[1] = id;
            NetUtils.WriteAscii(name.TrimEnd('+'), buffer, 2);
            NetUtils.WriteU16(x, buffer, 66);
            NetUtils.WriteU16(y, buffer, 68);
            NetUtils.WriteU16(z, buffer, 70);
            buffer[72] = rotx;
            buffer[73] = roty;
            Send(buffer);

            if (hasChangeModel)
            {
                UpdateModels();
            }
        }
예제 #10
0
        public static byte[] GetPositionPacket(byte id, ushort[] pos, ushort[] oldpos,
                                               byte[] rot, byte[] oldrot, byte realPitch, bool bot)
        {
            bool posChanged = false, oriChanged = false, absPosUpdate = false;

            if (oldpos[0] != pos[0] || oldpos[1] != pos[1] || oldpos[2] != pos[2])
            {
                posChanged = true;
            }
            if (oldrot[0] != rot[0] || oldrot[1] != rot[1])
            {
                oriChanged = true;
            }
            if (Math.Abs(pos[0] - oldpos[0]) > 32 || Math.Abs(pos[1] - oldpos[1]) > 32 || Math.Abs(pos[2] - oldpos[2]) > 32)
            {
                absPosUpdate = true;
            }
            // TODO: not sure why this is necessary for bots
            if (bot)
            {
                absPosUpdate = true;
            }

            byte[] buffer = null;
            if (absPosUpdate)
            {
                buffer    = new byte[10];
                buffer[0] = Opcode.EntityTeleport;
                buffer[1] = id;
                NetUtils.WriteU16(pos[0], buffer, 2);
                NetUtils.WriteU16(pos[1], buffer, 4);
                NetUtils.WriteU16(pos[2], buffer, 6);
                buffer[8] = rot[0];
                buffer[9] = realPitch;
            }
            else if (posChanged && oriChanged)
            {
                buffer    = new byte[7];
                buffer[0] = Opcode.RelPosAndOrientationUpdate;
                buffer[1] = id;
                buffer[2] = (byte)(pos[0] - oldpos[0]);
                buffer[3] = (byte)(pos[1] - oldpos[1]);
                buffer[4] = (byte)(pos[2] - oldpos[2]);
                buffer[5] = rot[0];
                buffer[6] = realPitch;
            }
            else if (posChanged)
            {
                buffer    = new byte[5];
                buffer[0] = Opcode.RelPosUpdate;
                buffer[1] = id;
                buffer[2] = (byte)(pos[0] - oldpos[0]);
                buffer[3] = (byte)(pos[1] - oldpos[1]);
                buffer[4] = (byte)(pos[2] - oldpos[2]);
            }
            else if (oriChanged)
            {
                buffer    = new byte[4];
                buffer[0] = Opcode.OrientationUpdate;
                buffer[1] = id;
                buffer[2] = rot[0];
                buffer[3] = realPitch;
            }
            return(buffer);
        }