Example #1
0
        public BulkChunks(Wrapped.Wrapped socket, Form1 mainform)
        {
            short columncount = socket.readShort();
            int   Datalength  = socket.readInt();
            bool  skylight    = socket.readBool();

            byte[] packdata = socket.readByteArray(Datalength);
            byte[] decompressed;


            byte[]  trim   = new byte[Datalength - 2];
            Chunk[] chunks = new Chunk[columncount];

            // Shoutout to BjorN64 for the simplification of this.
            Array.Copy(packdata, 2, trim, 0, Datalength - 2);

            // Decompress the data

            Classes.Decompressor dc = new Classes.Decompressor(trim);
            decompressed = dc.decompress();

            for (int i = 0; columncount > i; i++)
            {
                // Need to store this data so it's not lost as well..
                int   x       = socket.readInt();
                int   z       = socket.readInt();
                short pbitmap = socket.readShort();
                short abitmap = socket.readShort();

                chunks[i] = new Chunk(x, z, pbitmap, abitmap, skylight, true); // Assume true for Ground Up Continuous

                decompressed = chunks[i].getData(decompressed);                // Calls the chunk class to take all of the bytes it needs, and return whats left.
                mainform.Chunks.Add(chunks[i]);                                // Add the chunk to the main form so we can use it later.
            }
        }
Example #2
0
 public EntVelocity(Wrapped.Wrapped socket, Form1 mainform)
 {
     socket.readInt();
     socket.readShort();
     socket.readShort();
     socket.readShort();
 }
Example #3
0
        public itemData(Wrapped.Wrapped socket, Form1 mainform)
        {
            socket.readShort();
            socket.readShort();
            int txtlength = socket.readShort();

            socket.readByteArray(txtlength);
        }
Example #4
0
 public BlockAction(Wrapped.Wrapped socket, Form1 mainform)
 {
     socket.readInt();
     socket.readShort();
     socket.readInt();
     socket.readByte();
     socket.readByte();
     socket.readShort();
 }
Example #5
0
 public updateHealth(Wrapped.Wrapped sock, Form1 myform)
 {
     myform.health = sock.readShort();
     myform.hunger = sock.readShort();
     sock.readFloat();
     if (0 >= myform.health)
     {
         ClientResponse respawn = new ClientResponse(true, sock, myform, 1);
         myform.puts("Respawned..?");
     }
 }
Example #6
0
        public ChunkData(Wrapped.Wrapped socket, Form1 Mainform)
        {
            // Parse or unload a single chunk

            int   x        = socket.readInt();
            int   z        = socket.readInt();
            bool  groundup = socket.readBool();
            short pbitmap  = socket.readShort();
            short abitmap  = socket.readShort();
            int   size     = socket.readInt();

            byte[] data = socket.readByteArray(size);
            byte[] trim = new byte[size - 2];
            byte[] decompressed;


            // Remove first two bytes to array
            Array.Copy(data, 2, trim, 0, size - 2);

            // Decompress the data

            Classes.Decompressor DC = new Decompressor(trim);
            decompressed = DC.decompress();


            if (pbitmap == 0)
            {
                // Unload chunk, save ALL the ram!
                Classes.Chunk thischunk = null;

                foreach (Chunk f in Mainform.Chunks)
                {
                    if (f.x == x && f.z == z)
                    {
                        thischunk = f;
                        break;
                    }
                }

                if (thischunk != null)
                {
                    Mainform.Chunks.Remove(thischunk);
                    return;
                }
            }

            Chunk myChunk = new Chunk(x, z, pbitmap, abitmap, true, groundup); // Skylight assumed true..

            Mainform.puts("DC: " + decompressed.Length + " num: " + myChunk.numBlocks + " pbit: " + pbitmap);
            decompressed = myChunk.getData(decompressed);

            Mainform.Chunks.Add(myChunk); // Add to main form for use later.
        }
Example #7
0
        public updateTileEntity(Wrapped.Wrapped socket, Form1 mainform)
        {
            socket.readInt();
            socket.readShort();
            socket.readInt();
            socket.readByte();
            int length = socket.readShort();

            if (length != 0)
            {
                socket.readByteArray(length);
            }
        }
Example #8
0
        // Server-to-Client only

        public teams(Wrapped.Wrapped socket, Form1 Mainform)
        {
            List <string> players;
            string        teamDisplayname;
            string        teamPrefix;
            string        teamSuffix;
            byte          friendlyFire;
            short         playerCount;

            string teamName = socket.readString();
            byte   mode     = socket.readByte();

            if (mode == 0 || mode == 2)
            {
                teamDisplayname = socket.readString();
                teamPrefix      = socket.readString();
                teamSuffix      = socket.readString();
                friendlyFire    = socket.readByte();
            }
            if (mode == 0 || mode == 3 || mode == 4)
            {
                playerCount = socket.readShort();
                players     = new List <string>();

                for (int i = 1; i < playerCount; i++)
                {
                    players.Add(socket.readString());
                }
            }
        }
Example #9
0
 public EntEffect(Wrapped.Wrapped socket, Form1 Mainform)
 {
     socket.readInt();
     socket.readByte();
     socket.readByte();
     socket.readShort();
 }
Example #10
0
        public BlockChange(Wrapped.Wrapped socket, Form1 Mainform)
        {
            int chunkX, chunkZ;

            int   x       = socket.readInt();
            byte  y       = socket.readByte();
            int   z       = socket.readInt();
            short blockID = socket.readShort();

            socket.readByte();

            chunkX = (int)Math.Floor(decimal.Divide(x, 16));
            chunkZ = (int)Math.Floor(decimal.Divide(z, 16));

            Classes.Chunk thisChunk = null;

            foreach (Classes.Chunk b in Mainform.Chunks)
            {
                if (b.x == chunkX & b.z == chunkZ)
                {
                    thisChunk = b;
                    break;
                }
            }

            thisChunk.updateBlock(x, y, z, blockID);
        }
Example #11
0
 public SpawnExporb(Wrapped.Wrapped socket, Form1 mainform)
 {
     socket.readInt();
     socket.readInt();
     socket.readInt();
     socket.readInt();
     socket.readShort();
 }
Example #12
0
        public SetSlot(Wrapped.Wrapped socket, Form1 mainform)
        {
            byte      windowId = socket.readByte();
            short     slot     = socket.readShort();
            functions Parser   = new functions();

            Parser.readSlot(socket, true, mainform, slot);
        }
Example #13
0
 public updateSign(Wrapped.Wrapped socket, Form1 Mainform)
 {
     socket.readInt();
     socket.readShort();
     socket.readInt();
     socket.readString();
     socket.readString();
     socket.readString();
     socket.readString();
 }
Example #14
0
        public SpawnObj(Wrapped.Wrapped socket, Form1 mainform)
        {
            socket.readInt();
            socket.readByte();
            socket.readInt();
            socket.readInt();
            socket.readInt();
            socket.readByte();
            socket.readByte();
            // --
            int value = socket.readInt();

            if (value != 0)
            {
                socket.readShort();
                socket.readShort();
                socket.readShort();
            }
        }
Example #15
0
        void handle()
        {
            int    Dimention  = socket.readInt();
            byte   Difficulty = socket.readByte();
            byte   mode       = socket.readByte();
            short  height     = socket.readShort();
            string leveltype  = socket.readString();

            mainform.Chunks.Clear(); // Clear out the chunks.
        }
Example #16
0
        public PluginMessage(Wrapped.Wrapped socket, Form1 Mainform)
        {
            socket.readString();
            int length = socket.readShort();

            if (length != 0)
            {
                socket.readByteArray(length);
            }
        }
Example #17
0
        public SpawnMob(Wrapped.Wrapped socket, Form1 Mainform)
        {
            int  EID       = socket.readInt();
            byte type      = socket.readByte();
            int  X         = socket.readInt();
            int  Y         = socket.readInt();
            int  Z         = socket.readInt();
            byte Pitch     = socket.readByte();
            byte headPitch = socket.readByte();
            byte Yaw       = socket.readByte();

            socket.readShort();
            socket.readShort();
            socket.readShort();

            functions parser = new functions();

            parser.readMetadata(socket);

            Classes.Entity newMob = new Classes.Entity(EID, ((functions.entityId)type).ToString(), X, Y, Z, Yaw, Pitch, 0);
            Mainform.Entitys.Add(newMob);
        }
Example #18
0
        public Classes.Item returnSlot(Wrapped.Wrapped socket)
        {
            int blockID = socket.readShort();

            if (blockID == -1)
            {
                return(null);
            }

            byte  itemCount = socket.readByte();
            short damage    = socket.readShort();
            int   NBTLength = socket.readShort();

            if (NBTLength == -1)
            {
                return(new Classes.Item(blockID, itemCount, damage, 0));
            }

            socket.readByteArray(NBTLength);

            return(new Classes.Item(blockID, itemCount, damage, 0));
        }
Example #19
0
        public creativeInventory(Wrapped.Wrapped socket, Form1 mainform)
        {
            functions helper = new functions();

            int slot = socket.readShort();

            Classes.Item thisitem = helper.returnSlot(socket);

            if (slot == -1)
            {
                ClickWindow click2 = new ClickWindow(socket, mainform, -999, 0, 0, thisitem);
            }
        }
Example #20
0
        void handle()

        {
            short secretLength = socket.readShort();

            byte[] sharedSecret = socket.readByteArray(secretLength);
            short  tokenLength  = socket.readShort();

            byte[] token;

            if (tokenLength != 0)
            {
                token = socket.readByteArray(tokenLength);
            }

            if (tokenLength == 0 && secretLength == 0)

            {
                socket.EncEnabled = true;
                ClientResponse response = new ClientResponse(true, socket, form, 0);
                form.puts("Encryption enabled.");
            }
        }
Example #21
0
        public void readMetadata(Wrapped.Wrapped socket)
        {
            // read metadata from socket
            do
            {
                byte item = socket.readByte();

                if (item == 127)
                {
                    break;
                }
                int index = item & 0x1F;
                int type  = item >> 5;

                switch (type)
                {
                case 0:
                    socket.readByte();
                    break;

                case 1:
                    socket.readShort();
                    break;

                case 2:
                    socket.readInt();
                    break;

                case 3:
                    socket.readFloat();
                    break;

                case 4:
                    socket.readString();
                    break;

                case 5:
                    readSlot(socket);
                    break;

                case 6:
                    socket.readInt();
                    socket.readInt();
                    socket.readInt();
                    break;
                }
            } while (true);
        }
Example #22
0
        public ConfirmTransaction(Wrapped.Wrapped socket, Form1 mainform)
        {
            // Should only be sent if we actually receive one with a "false" for accepted.
            byte  windowID     = socket.readByte();
            short actionNumber = socket.readShort();
            bool  accepted     = socket.readBool();

            if (accepted == false)
            {
                socket.writeByte(0x6A);
                socket.writeByte(windowID);
                socket.writeShort(actionNumber);
                socket.writeBool(accepted);
                ClickWindow cw = new ClickWindow(socket, mainform, -999, 0, 0, null); // If we're holding something on our cursor, drop it.
            }
        }
Example #23
0
        public SpawnNamedEntity(Wrapped.Wrapped socket, Form1 mainform)
        {
            int       EID      = socket.readInt();
            string    Name     = socket.readString();
            int       X        = socket.readInt();
            int       Y        = socket.readInt();
            int       Z        = socket.readInt();
            byte      Yaw      = socket.readByte();
            byte      Pitch    = socket.readByte();
            short     heldItem = socket.readShort();
            functions parser   = new functions();

            parser.readMetadata(socket);

            Classes.Entity newPlayer = new Classes.Entity(EID, Name, X, Y, Z, Yaw, Pitch, heldItem);
            mainform.Entitys.Add(newPlayer);
        }
Example #24
0
        public MultiBlockChange(Wrapped.Wrapped socket, Form1 mainform)
        {
            int chunkX   = socket.readInt();
            int chunkZ   = socket.readInt();
            int blocks   = socket.readShort();
            int datasize = socket.readInt();

            byte[] data      = socket.readByteArray(datasize);
            Chunk  thischunk = null;

            foreach (Chunk b in mainform.Chunks)
            {
                if (b.x == chunkX & b.z == chunkZ)
                {
                    thischunk = b;
                    break;
                }
            }

            if (thischunk == null)
            {
                throw new Exception("Attempted to access an uninitilized chunk.");
            }

            // The below parsing method is thanks to redstone_bot, translated from ruby to C# by myself.

            for (int i = 0; i < blocks - 1; i++)
            {
                byte[] blockData = new byte[4];
                Array.Copy(data, (i * 4), blockData, 0, 4);

                int z        = (blockData[0] & 0x0F);
                int x        = (blockData[0] >> 4) & 0x0F;
                int y        = (blockData[1]);
                int blockId  = (blockData[2] << 4) | ((blockData[3] & 0xF0) >> 4);
                int metaData = blockData[3] & 0xF;

                // X,Z Are rel. to Chunk, so convert to chunk coords.. (also, this part down is my own code again)
                x = (chunkX * 16) + x;
                z = (chunkZ * 16) + z;

                thischunk.updateBlock(x, y, z, blockId);
            }
        }
Example #25
0
        public entProps(Wrapped.Wrapped socket, Form1 mainform)
        {
            int entId     = socket.readInt();
            int propCount = socket.readInt();

            for (int b = 0; b < propCount; b++)
            {
                string key        = socket.readString();
                double value      = socket.readDouble();
                short  listLength = socket.readShort();

                for (int i = 0; i < listLength; i++)
                {
                    long   msb     = socket.readLong();
                    long   lsb     = socket.readLong();
                    double ammount = socket.readDouble();
                    byte   op      = socket.readByte();
                }
            }
        }
Example #26
0
        public BlockChange(Wrapped.Wrapped socket, Form1 Mainform)
        {
            int chunkX, chunkZ;

            int   x       = socket.readInt();
            byte  y       = socket.readByte();
            int   z       = socket.readInt();
            short blockID = socket.readShort();

            socket.readByte();

            chunkX = (int)Math.Floor(decimal.Divide(x, 16));
            chunkZ = (int)Math.Floor(decimal.Divide(z, 16));

            Classes.Chunk thisChunk = null;

            foreach (Classes.Chunk b in Mainform.Chunks)
            {
                if (b.x == chunkX & b.z == chunkZ)
                {
                    thisChunk = b;
                    break;
                }
            }

            if (blockID == 15 && Mainform.importing == true)
            {
                Mainform.importing = false;
                Classes.Importer Importer = new Classes.Importer(Mainform, Mainform.importName, x, (int)y, z);
                //  Thread importThread = new Thread(Importer.import);
                // importThread.Start();
                Importer.import();
            }
            if (thisChunk != null)
            {
                thisChunk.updateBlock(x, y, z, blockID);
            }
        }
Example #27
0
        void handle()
        {
            // The Entity we're updating..

            int EID = socket.readInt();

            // Which slot we're updating (0 = held, 1-4 = armour slots)

            short slot = socket.readShort();

            //Have to handle the item now.

            if (EID == mainform.EntityID)
            {
                functions slotHandler = new functions();
                slotHandler.readSlot(socket, true, mainform, slot);
            }
            else
            {
                functions slotHandler = new functions();
                slotHandler.otherSlot(socket, mainform, EID, slot);
            }
        }
Example #28
0
        public setWindowItems(Wrapped.Wrapped socket, Form1 mainform)
        {
            byte      windowid = socket.readByte();
            int       count    = socket.readShort();
            int       asdf     = 0;
            functions parser   = new functions();

            if (windowid == 0)
            {
                for (short i = 0; i < count; i++)
                {
                    parser.readSlot(socket, true, mainform, i);
                    asdf++;
                }
            }
            else
            {
                while (count != 0)
                {
                    parser.readSlot(socket);
                    count--;
                }
            }
        }
Example #29
0
        void handle()
        {
            // This packet is complicated, so I will comment the process.
            // Let's get the data off the line first..

            string serverID  = sock.readString();
            short  keyLength = sock.readShort();
            short  verifyLength;

            byte[] key;
            byte[] token;
            key          = sock.readByteArray(keyLength);
            verifyLength = sock.readShort();
            token        = sock.readByteArray(verifyLength);

            //Here, we need some random bytes to use as a shared key with the server.

            RandomNumberGenerator random = RandomNumberGenerator.Create();

            random.GetBytes(myform.sharedkey);

            // AsnKeyParser is a part of the cryptography.dll, which is simply a compiled version
            // of SMProxy's Cryptography.cs, with the server side parts stripped out.
            // You pass it the key data and ask it to parse, and it will
            // Extract the server's public key, then parse that into RSA for us.

            AsnKeyParser  keyParser = new AsnKeyParser(key);
            RSAParameters Dekey     = keyParser.ParseRSAPublicKey();

            // Now we create an encrypter, and encrypt the token sent to us by the server
            // as well as our newly made shared key (Which can then only be decrypted with the server's private key)
            // and we send it to the server.
            RSACryptoServiceProvider cryptoService = new RSACryptoServiceProvider();

            cryptoService.ImportParameters(Dekey);
            byte[] EncryptedSecret = cryptoService.Encrypt(myform.sharedkey, false);
            byte[] EncryptedVerfy  = cryptoService.Encrypt(token, false);

            // I pass this information back up (Unencrypted) to the main form.
            // This allows me to have it ready for when I need this later.

            myform.ServerID  = serverID;
            myform.token     = token;
            myform.PublicKey = key;


            if (serverID != "-" && myform.onlineMode)
            {
                // Verify with Minecraft.net, if need be.
                // At this point, the server requires a hash containing the server id,
                // shared key, and original public key. So we make this, and then pass to Minecraft.net

                List <byte> hashlist = new List <byte>();
                hashlist.AddRange(System.Text.Encoding.ASCII.GetBytes(serverID));
                hashlist.AddRange(myform.sharedkey);
                hashlist.AddRange(key);
                byte[] hashData = hashlist.ToArray();
                string hash     = JavaHexDigest(hashData);
                myform.serverHash = hash;

                Minecraft_Net_Interaction verify = new Minecraft_Net_Interaction();
                if (!verify.VerifyName(myform.username, myform.sessionId, hash))
                {
                    myform.puts("Failed to verify name with minecraft.net");
                    sock._stream.Close();
                    myform.sessionId = null;
                    return;
                }
            }
            else
            {
                // Skip Verification, user is not online.
                myform.puts("Skipping verification.");
            }

            // Sets up the socket for encryption, but does not enable it yet.
            sock.InitEncryption(myform.sharedkey);

            // Respond to server.
            EncResponse Response = new EncResponse(sock, myform, EncryptedVerfy, EncryptedSecret, true);
        }
Example #30
0
 void handle()
 {
     myform.selectedSlot = socket.readShort();
 }