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. } }
public itemData(Wrapped.Wrapped socket, Form1 mainform) { socket.readShort(); socket.readShort(); int txtlength = socket.readShort(); socket.readByteArray(txtlength); }
public PluginMessage(Wrapped.Wrapped socket, Form1 Mainform) { socket.readString(); int length = socket.readShort(); if (length != 0) { socket.readByteArray(length); } }
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. }
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); } }
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."); } }
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); } }
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)); }
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); }
public void readSlot(Wrapped.Wrapped socket, bool inventory = false, Form1 Mainform = null, short slot = 500) { // Read's slot data off the socket, and if the options are provided, will also add to the bot's inventory. bool delete = false; Classes.Item existing = null; // Just in case. if (inventory == true & Mainform == null) { throw new Exception("If inventory is true, you must include a main form."); } if ((inventory == true) & slot == 500) { throw new Exception("If inventory is true, you must include which slot to add to."); } // Delete the existing inventory data if it already exists. if (inventory == true) { foreach (Classes.Item b in Mainform.inventory) { if (b.slot == slot) { delete = true; existing = b; break; } } if (delete == true) { Mainform.inventory.Remove(existing); } } int blockID = socket.readShort(); if (blockID == -1) { return; } byte itemCount = socket.readByte(); short damage = socket.readShort(); int NBTLength = socket.readShort(); if (NBTLength == -1) { if (inventory == true) { Mainform.inventory.Add(new Classes.Item(blockID, itemCount, damage, slot)); } return; } socket.readByteArray(NBTLength); if (inventory == true) { Mainform.inventory.Add(new Classes.Item(blockID, itemCount, damage, slot)); } }
public void otherSlot(Wrapped.Wrapped socket, Form1 Mainform, int EID, int slot) { Entity thisEnt = getEntbyID(EID, Mainform); // Entity we are modifying int blockID = socket.readShort(); if (blockID == -1) { switch (slot) { case 0: thisEnt.held = new Item(0, 1, 0, 0); break; case 1: thisEnt.boots = new Item(0, 1, 0, 0); break; case 2: thisEnt.leggins = new Item(0, 1, 0, 0); break; case 3: thisEnt.chestplate = new Item(0, 1, 0, 0); break; case 4: thisEnt.helmet = new Item(0, 1, 0, 0); break; } return; } byte itemCount = socket.readByte(); short damage = socket.readShort(); int NBTLength = socket.readShort(); if (NBTLength == -1) { switch (slot) { case 0: thisEnt.held = new Item(blockID, itemCount, damage, (short)slot); break; case 1: thisEnt.boots = new Item(blockID, itemCount, damage, (short)slot); break; case 2: thisEnt.leggins = new Item(blockID, itemCount, damage, (short)slot); break; case 3: thisEnt.chestplate = new Item(blockID, itemCount, damage, (short)slot); break; case 4: thisEnt.helmet = new Item(blockID, itemCount, damage, (short)slot); break; } return; } socket.readByteArray(NBTLength); switch (slot) { case 0: thisEnt.held = new Item(blockID, itemCount, damage, (short)slot); break; case 1: thisEnt.boots = new Item(blockID, itemCount, damage, (short)slot); break; case 2: thisEnt.leggins = new Item(blockID, itemCount, damage, (short)slot); break; case 3: thisEnt.chestplate = new Item(blockID, itemCount, damage, (short)slot); break; case 4: thisEnt.helmet = new Item(blockID, itemCount, damage, (short)slot); break; } }
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]; Array.Reverse(packdata); Array.Copy(packdata, trim, Datalength - 2); Array.Reverse(trim); // 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(); Chunk mychunk = new Chunk(x, z, pbitmap, abitmap, skylight); chunks[i] = mychunk; } int offset = 0; foreach (Chunk b in chunks) { for (int i = 0; i < 16; i++) { if (Convert.ToBoolean(b.pbitmap & (1 << i))) { byte[] newBlocks = new byte[4096]; byte[] temp = b.blocks; Array.Copy(decompressed, offset, newBlocks, 0, 4096); if (b.blocks == null) { b.blocks = newBlocks; } else { b.blocks = new byte[temp.Length + 4096]; temp.CopyTo(b.blocks, 0); newBlocks.CopyTo(b.blocks, temp.Length); } b.numBlocks += 4096; offset += 4096; } } mainform.Chunks.Add(b); if (b.abitmap != 0) { throw new Exception(); } // we need to adjust the offset in compensation for additional metadata included with every chunk.. int additional = 0; int Nibbleinfo = b.numBlocks / 2; int totalSections = b.numBlocks / 4096; if (skylight == true) { additional = (totalSections * Nibbleinfo) + (totalSections * Nibbleinfo) + (totalSections * Nibbleinfo); } else { additional = (totalSections * Nibbleinfo) + (totalSections * Nibbleinfo); } additional += 256; offset += additional; //Array.Copy(decompressed, b.blocks, b.blocks.Length); //temp = new byte[decompressed.Length - b.blocks.Length]; //Array.Copy(decompressed, b.blocks.Length, temp, 0, decompressed.Length - b.blocks.Length); //decompressed = temp; //mainform.Chunks.Add(b); // parseChunk(b,mainform); } }