From d8dc0cd6b0dd53e1d9d9ce8e9f24d1deb3aa73b4 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 15 Apr 2020 16:32:49 +0200 Subject: [PATCH] Working full chunk techhider version without debug output Signed-off-by: Lixfel --- .../fightsystem/utils/TechHider_15.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/FightSystem_15/src/de/steamwar/fightsystem/utils/TechHider_15.java b/FightSystem_15/src/de/steamwar/fightsystem/utils/TechHider_15.java index 4bbb628..4e10268 100644 --- a/FightSystem_15/src/de/steamwar/fightsystem/utils/TechHider_15.java +++ b/FightSystem_15/src/de/steamwar/fightsystem/utils/TechHider_15.java @@ -35,6 +35,9 @@ public class TechHider_15 { } static void chunkHider(){ + /* + * Bevor editing this function read and understand: https://wiki.vg/Chunk_Format + * */ ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) { @Override public void onPacketSending(PacketEvent e) { @@ -114,12 +117,15 @@ public class TechHider_15 { } i += actPaletteLength; } + + //We modify only the chunk palette for performance reasons int dataArrayLength = ITechHider.readVarInt(data, i); int dataArrayLengthLength = ITechHider.readVarIntLength(data, i); buffer.writeBytes(data, i, dataArrayLength * 8 + dataArrayLengthLength); i += dataArrayLengthLength; i += dataArrayLength * 8; }else{ + //Full Chunk/no palette, so the chunk has to be crawled through int dataArrayLength = ITechHider.readVarInt(data, i); int dataArrayLengthLength = ITechHider.readVarIntLength(data, i); buffer.writeBytes(data, i, dataArrayLengthLength); @@ -128,8 +134,6 @@ public class TechHider_15 { ByteBuf chunkData = UnpooledByteBufAllocator.DEFAULT.directBuffer(dataArrayLength * 8); chunkData.writeBytes(data, i, dataArrayLength * 8); - int arrayEnd = dataArrayLength * 8 + i; - int bitsOver = 0; // Anzahl an Bits, die aus dem letzten Durchlauf noch über sind int lastBits = 0; // Die letzten Bits aus dem vorigen Durchlauf Bukkit.broadcastMessage("Full Chunk!"); @@ -147,24 +151,21 @@ public class TechHider_15 { if(currentPos > 50){ //64 - 14, Prüfen auf Ende des Longs int offset = 14 - (currentPos - 50); - if(arrayEnd <= i+15) - System.out.println("Array Overflow!!!! i: " + i + " currentPos:" + currentPos + " bitsOver:" + bitsOver + " lastBits:" + lastBits); - blockId |= (data[i+14] << (offset + 8) | data[i+15] << offset) & 0x3FFF; } if(Config.HiddenBlocks.contains(blockId)) blockId = Config.ObfuscateWith; - if(blockId > 11336) - System.out.println("WTF? blockId: " + blockId); + //TODO: Fix last edge cases of Full Chunk techhider + //if(blockId > 11336) Should not occur, but occurs result <<= 14; result |= blockId; currentPos -= 14; } - if(currentPos > -14){ //Überprüfen der ersten Bits + if(currentPos > -14){ // Check the first bits of the chunk int blockId = ((int)values << -currentPos | lastBits) & 0x3FFF; if(Config.HiddenBlocks.contains(blockId)) blockId = Config.ObfuscateWith; @@ -183,9 +184,7 @@ public class TechHider_15 { } numChunkSections--; } - if(data.length - i != 0) - Bukkit.getLogger().log(Level.WARNING, "There should be no more data. i: " + i + " data.length: " + data.length + " data[i]:" + data[i]); - buffer.writeBytes(data, i, data.length - i); + buffer.writeBytes(data, i, data.length - i); // MC appends a 0 byte at the end if there is a full chunk, idk why if(changed){ data = new byte[buffer.readableBytes()];