From c7a48f36f2ffcc536b8cfd1a063030daa461a9e9 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 19 May 2020 09:42:49 +0200 Subject: [PATCH] Simplified 1.12-Techhider Signed-off-by: Lixfel --- .../fightsystem/utils/TechHider_12.java | 64 ++++++++----------- .../src/de/steamwar/fightsystem/Config.java | 2 + .../steamwar/fightsystem/utils/TechHider.java | 2 +- 3 files changed, 28 insertions(+), 40 deletions(-) diff --git a/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java index 0a5e8c7..537dc90 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java @@ -6,19 +6,20 @@ import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.reflect.StructureModifier; +import com.comphenix.protocol.wrappers.nbt.NbtBase; import com.comphenix.protocol.wrappers.nbt.NbtCompound; -import com.comphenix.protocol.wrappers.nbt.NbtFactory; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.IFightSystem; import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; import net.minecraft.server.v1_12_R1.PacketPlayOutMapChunk; +import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_12_R1.CraftChunk; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; import static de.steamwar.fightsystem.utils.ITechHider.bypass; @@ -50,19 +51,18 @@ class TechHider_12 { packet = packet.shallowClone(); e.setPacket(packet); - StructureModifier list = packet.getSpecificModifier(List.class); - List nmsTags = list.read(0); + StructureModifier>> list = packet.getListNbtModifier(); + List> nmsTags = list.read(0); boolean changed = false; - List newNmsTags = new ArrayList(nmsTags.size()); - for(Object nmsTag : nmsTags){ - NbtCompound nbt = NbtFactory.fromNMSCompound(nmsTag); - if(Config.HiddenBlockEntities.contains(nbt.getString("id"))) + for(int i = nmsTags.size() - 1; i >= 0; i--){ + NbtCompound nbt = (NbtCompound)nmsTags.get(i); + if(Config.HiddenBlockEntities.contains(nbt.getString("id"))){ + nmsTags.remove(i); changed = true; - else - newNmsTags.add(nmsTag); + } } if(changed) - list.write(0, newNmsTags); + list.write(0, nmsTags); changed = false; StructureModifier byteArray = packet.getByteArrays(); @@ -73,48 +73,34 @@ class TechHider_12 { while(i < data.length){ byte bitsPerBlock = data[i++]; buffer.writeByte(bitsPerBlock); - if(bitsPerBlock < 4) - bitsPerBlock = 4; - else if(bitsPerBlock > 8){ - bitsPerBlock = 13; - buffer.writeByte(data[++i]); - } if(bitsPerBlock != 13){ int paletteLength = ITechHider.readVarInt(data, i); int paletteLengthLength = ITechHider.readVarIntLength(data, i); buffer.writeBytes(data, i, paletteLengthLength); i += paletteLengthLength; - List palette = new ArrayList<>(paletteLength); - for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){ - palette.add(ITechHider.readVarInt(data, i)); - i += ITechHider.readVarIntLength(data, i); - } - int replacement = 0; - for(int entry : palette){ - int blockId = entry >> 4; - if(Config.HiddenBlocks.contains(blockId)){ - while(palette.contains((++replacement) << 4)); - entry = replacement << 4; + for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){ + int entry = ITechHider.readVarInt(data, i); + i += ITechHider.readVarIntLength(data, i); + + if(Config.HiddenBlocks.contains(entry >> 4)){ + entry = obfuscateShift4; changed = true; } buffer.writeBytes(ITechHider.writeVarInt(entry)); } - - 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{ - int dataArrayLength = ITechHider.readVarInt(data, i); - int dataArrayLengthLength = ITechHider.readVarIntLength(data, i); - buffer.writeBytes(data, i, dataArrayLength*8 + dataArrayLengthLength); - i += dataArrayLengthLength; - i += dataArrayLength * 8; + buffer.writeByte(data[++i]); //Empty palette + Bukkit.getLogger().log(Level.SEVERE, "Full chunk 1.12 occured"); } + int dataArrayLength = ITechHider.readVarInt(data, i); + int dataArrayLengthLength = ITechHider.readVarIntLength(data, i); + buffer.writeBytes(data, i, dataArrayLength*8 + dataArrayLengthLength); + i += dataArrayLengthLength; + i += dataArrayLength * 8; + buffer.writeBytes(data, i, 4096); i += 4096; //Skylight (Not in Nether/End!!!) 2048 + Blocklight 2048 } diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 88bb7dc..ff058e8 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -103,6 +103,7 @@ public class Config { public static final List ForbiddenItems; //tech hider parameter + public static final boolean TechhiderActive; public static final Set HiddenBlocks; public static final Set HiddenBlockTags; public static final Set HiddenBlockEntities; @@ -208,6 +209,7 @@ public class Config { HiddenBlockEntities = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlockEntities"))); ObfuscateWith = config.getInt("Techhider.ObfuscateWith"); ObfuscateWithTag = config.getString("Techhider.ObfuscateWithTag"); + TechhiderActive = config.getBoolean("Techhider.Active"); if(schemsizeX < 0){ SchemsizeX = -schemsizeX; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java index 00a2a71..fa2f14f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java @@ -236,6 +236,6 @@ public class TechHider { } private static boolean disabled(){ - return Config.OnlyPublicSchematics || Config.test(); + return Config.OnlyPublicSchematics || Config.test() || !Config.TechhiderActive; } }