From 1957c6a472aee7782359a9330a655ef7a3773cb5 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 24 Jun 2022 17:38:44 +0200 Subject: [PATCH 1/3] CoreHider (without removal) Signed-off-by: Lixfel --- .../fightsystem/utils/BlockIdWrapper14.java | 29 -- .../src/de/steamwar/techhider/BlockIds14.java | 52 ++++ .../ChunkHider14.java} | 39 +-- .../steamwar/techhider/ProtocolWrapper14.java | 16 +- .../fightsystem/utils/BlockIdWrapper15.java | 29 -- .../src/de/steamwar/techhider/BlockIds15.java | 52 ++++ .../fightsystem/utils/BlockIdWrapper18.java | 33 --- .../fightsystem/utils/ProtocolWrapper18.java | 48 ---- .../src/de/steamwar/techhider/BlockIds18.java | 57 ++++ .../ChunkHider18.java} | 82 +++--- .../steamwar/techhider/ProtocolWrapper18.java | 77 ++++++ .../fightsystem/utils/BlockIdWrapper19.java | 33 --- .../fightsystem/utils/ProtocolWrapper19.java | 38 --- .../src/de/steamwar/techhider/BlockIds19.java | 57 ++++ .../ChunkHider19.java} | 10 +- .../steamwar/techhider/ProtocolWrapper19.java | 67 +++++ .../fightsystem/utils/BlockIdWrapper8.java | 21 -- .../fightsystem/utils/ProtocolWrapper8.java | 50 ---- .../src/de/steamwar/techhider/BlockIds8.java | 38 +++ .../ChunkHider8.java} | 11 +- .../steamwar/techhider/ProtocolWrapper8.java | 76 ++++++ .../ChunkHider9.java} | 57 ++-- .../de/steamwar/fightsystem/FightSystem.java | 7 +- .../countdown/EnternCountdown.java | 8 +- .../steamwar/fightsystem/fight/FightTeam.java | 9 +- .../fightsystem/listener/Recording.java | 13 +- .../fightsystem/record/PacketProcessor.java | 9 +- .../steamwar/fightsystem/record/REntity.java | 33 +-- .../fightsystem/utils/BlockIdWrapper.java | 5 - .../fightsystem/utils/ProtocolWrapper.java | 10 - .../steamwar/fightsystem/utils/TechHider.java | 247 ------------------ .../fightsystem/utils/TechHiderWrapper.java | 98 +++++++ .../src/de/steamwar/techhider/BlockIds.java | 33 +++ .../src/de/steamwar/techhider/ChunkHider.java | 34 +++ .../ProtocolUtils.java} | 117 ++++++--- .../steamwar/techhider/ProtocolWrapper.java | 41 +++ .../src/de/steamwar/techhider/TechHider.java | 128 +++++++++ 37 files changed, 1044 insertions(+), 720 deletions(-) create mode 100644 FightSystem_14/src/de/steamwar/techhider/BlockIds14.java rename FightSystem_14/src/de/steamwar/{fightsystem/utils/TechHider14.java => techhider/ChunkHider14.java} (78%) rename FightSystem_12/src/de/steamwar/fightsystem/utils/ProtocolWrapper12.java => FightSystem_14/src/de/steamwar/techhider/ProtocolWrapper14.java (68%) create mode 100644 FightSystem_15/src/de/steamwar/techhider/BlockIds15.java create mode 100644 FightSystem_18/src/de/steamwar/techhider/BlockIds18.java rename FightSystem_18/src/de/steamwar/{fightsystem/utils/TechHider18.java => techhider/ChunkHider18.java} (65%) create mode 100644 FightSystem_18/src/de/steamwar/techhider/ProtocolWrapper18.java create mode 100644 FightSystem_19/src/de/steamwar/techhider/BlockIds19.java rename FightSystem_19/src/de/steamwar/{fightsystem/utils/TechHider19.java => techhider/ChunkHider19.java} (75%) create mode 100644 FightSystem_19/src/de/steamwar/techhider/ProtocolWrapper19.java create mode 100644 FightSystem_8/src/de/steamwar/techhider/BlockIds8.java rename FightSystem_8/src/de/steamwar/{fightsystem/utils/TechHider8.java => techhider/ChunkHider8.java} (75%) create mode 100644 FightSystem_8/src/de/steamwar/techhider/ProtocolWrapper8.java rename FightSystem_9/src/de/steamwar/{fightsystem/utils/TechHider9.java => techhider/ChunkHider9.java} (65%) delete mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java create mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java create mode 100644 FightSystem_Core/src/de/steamwar/techhider/BlockIds.java create mode 100644 FightSystem_Core/src/de/steamwar/techhider/ChunkHider.java rename FightSystem_Core/src/de/steamwar/{fightsystem/utils/ProtocolAPI.java => techhider/ProtocolUtils.java} (62%) create mode 100644 FightSystem_Core/src/de/steamwar/techhider/ProtocolWrapper.java create mode 100644 FightSystem_Core/src/de/steamwar/techhider/TechHider.java diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java index e2a8bff..3fdc6db 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java @@ -19,16 +19,13 @@ package de.steamwar.fightsystem.utils; -import de.steamwar.fightsystem.Config; import net.minecraft.server.v1_14_R1.*; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_14_R1.CraftWorld; import org.bukkit.craftbukkit.v1_14_R1.block.CraftBlock; -import java.util.HashSet; import java.util.Objects; -import java.util.Set; public class BlockIdWrapper14 implements BlockIdWrapper { @Override @@ -46,32 +43,6 @@ public class BlockIdWrapper14 implements BlockIdWrapper { cworld.getChunkProvider().flagDirty(pos); } - @Override - public Set getHiddenBlockIds() { - Set hiddenBlockIds = new HashSet<>(); - for(String tag : Config.HiddenBlocks){ - for(IBlockData data : IRegistry.BLOCK.get(new MinecraftKey(tag)).getStates().a()){ - hiddenBlockIds.add(net.minecraft.server.v1_14_R1.Block.getCombinedId(data)); - } - } - - if(Config.HiddenBlocks.contains("water")){ - Fluid water = FluidTypes.WATER.a(false); - for(IBlockData data : net.minecraft.server.v1_14_R1.Block.REGISTRY_ID){ - if(data.p() == water){ - hiddenBlockIds.add(net.minecraft.server.v1_14_R1.Block.getCombinedId(data)); - } - } - } - - return hiddenBlockIds; - } - - @Override - public int getObfuscateWith() { - return net.minecraft.server.v1_14_R1.Block.getCombinedId(IRegistry.BLOCK.get(new MinecraftKey(Config.ObfuscateWith)).getBlockData()); - } - @Override public Object getPose(boolean sneaking) { return sneaking ? EntityPose.SNEAKING : EntityPose.STANDING; diff --git a/FightSystem_14/src/de/steamwar/techhider/BlockIds14.java b/FightSystem_14/src/de/steamwar/techhider/BlockIds14.java new file mode 100644 index 0000000..1a946ef --- /dev/null +++ b/FightSystem_14/src/de/steamwar/techhider/BlockIds14.java @@ -0,0 +1,52 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ + +package de.steamwar.techhider; + +import net.minecraft.server.v1_14_R1.*; +import org.bukkit.Material; + +import java.util.HashSet; +import java.util.Set; + +public class BlockIds14 implements BlockIds { + @Override + public int materialToId(Material material) { + return Block.getCombinedId(IRegistry.BLOCK.get(new MinecraftKey(material.name().toLowerCase())).getBlockData()); + } + + @Override + public Set materialToAllIds(Material material) { + Set ids = new HashSet<>(); + for(IBlockData data : IRegistry.BLOCK.get(new MinecraftKey(material.name().toLowerCase())).getStates().a()) { + ids.add(Block.getCombinedId(data)); + } + + if(material == Material.WATER){ + Fluid water = FluidTypes.WATER.a(false); + for(IBlockData data : Block.REGISTRY_ID){ + if(data.p() == water){ + ids.add(Block.getCombinedId(data)); + } + } + } + + return ids; + } +} diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider14.java b/FightSystem_14/src/de/steamwar/techhider/ChunkHider14.java similarity index 78% rename from FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider14.java rename to FightSystem_14/src/de/steamwar/techhider/ChunkHider14.java index e5674b6..eae64df 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider14.java +++ b/FightSystem_14/src/de/steamwar/techhider/ChunkHider14.java @@ -1,7 +1,7 @@ -/* +/* This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam + + Copyright (C) 2021 SteamWar.de-Serverteam This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by @@ -15,20 +15,21 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ -package de.steamwar.fightsystem.utils; +package de.steamwar.techhider; import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; import java.nio.ByteBuffer; import java.nio.LongBuffer; +import java.util.Set; -public class TechHider14 extends TechHider9 { +public class ChunkHider14 extends ChunkHider9 { @Override - protected byte[] dataHider(byte[] data, Integer primaryBitMask) { + protected byte[] dataHider(int obfuscationTarget, Set obfuscate, byte[] data, Integer primaryBitMask) { ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100); int i = 0; @@ -43,16 +44,16 @@ public class TechHider14 extends TechHider9 { buffer.writeByte(bitsPerBlock); if(bitsPerBlock < 9){ - int paletteLength = TechHider.readVarInt(data, i); - int paletteLengthLength = TechHider.readVarIntLength(data, i); + int paletteLength = ProtocolUtils.readVarInt(data, i); + int paletteLengthLength = ProtocolUtils.readVarIntLength(data, i); buffer.writeBytes(data, i, paletteLengthLength); i += paletteLengthLength; for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){ - int blockId = TechHider.readVarInt(data, i); - int actPaletteLength = TechHider.readVarIntLength(data, i); + int blockId = ProtocolUtils.readVarInt(data, i); + int actPaletteLength = ProtocolUtils.readVarIntLength(data, i); - if(hiddenBlockIds.contains(blockId)){ - buffer.writeBytes(TechHider.writeVarInt(obfuscateWith)); + if(obfuscate.contains(blockId)){ + buffer.writeBytes(ProtocolUtils.writeVarInt(obfuscationTarget)); }else{ buffer.writeBytes(data, i, actPaletteLength); } @@ -60,15 +61,15 @@ public class TechHider14 extends TechHider9 { } //We modify only the chunk palette for performance reasons - int dataArrayLength = TechHider.readVarInt(data, i); - int dataArrayLengthLength = TechHider.readVarIntLength(data, i); + int dataArrayLength = ProtocolUtils.readVarInt(data, i); + int dataArrayLengthLength = ProtocolUtils.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 = TechHider.readVarInt(data, i); - int dataArrayLengthLength = TechHider.readVarIntLength(data, i); + int dataArrayLength = ProtocolUtils.readVarInt(data, i); + int dataArrayLengthLength = ProtocolUtils.readVarIntLength(data, i); buffer.writeBytes(data, i, dataArrayLengthLength); i += dataArrayLengthLength; @@ -76,8 +77,8 @@ public class TechHider14 extends TechHider9 { VariableValueArray values = new VariableValueArray(bitsPerBlock, dataArrayLength, source.asLongBuffer()); for(int pos = 0; pos < 4096; pos++){ - if(hiddenBlockIds.contains(values.get(pos))){ - values.set(pos, obfuscateWith); + if(obfuscate.contains(values.get(pos))){ + values.set(pos, obfuscationTarget); } } diff --git a/FightSystem_12/src/de/steamwar/fightsystem/utils/ProtocolWrapper12.java b/FightSystem_14/src/de/steamwar/techhider/ProtocolWrapper14.java similarity index 68% rename from FightSystem_12/src/de/steamwar/fightsystem/utils/ProtocolWrapper12.java rename to FightSystem_14/src/de/steamwar/techhider/ProtocolWrapper14.java index 650fb41..bb52f52 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/utils/ProtocolWrapper12.java +++ b/FightSystem_14/src/de/steamwar/techhider/ProtocolWrapper14.java @@ -17,30 +17,32 @@ along with this program. If not, see . */ -package de.steamwar.fightsystem.utils; +package de.steamwar.techhider; import com.comphenix.tinyprotocol.Reflection; +import org.bukkit.Material; import org.bukkit.entity.Player; +import java.util.Set; import java.util.function.BiFunction; import java.util.function.UnaryOperator; -public class ProtocolWrapper12 extends ProtocolWrapper8 { +public class ProtocolWrapper14 extends ProtocolWrapper8 { @Override - public BiFunction blockBreakHiderGenerator(Class blockBreakPacket){ - UnaryOperator blockBreakCloner = ProtocolAPI.shallowCloneGenerator(blockBreakPacket); + public BiFunction blockBreakHiderGenerator(Class blockBreakPacket, Object obfuscationTarget, Set obfuscate, TechHider.BypassEvaluator bypass) { + UnaryOperator blockBreakCloner = ProtocolUtils.shallowCloneGenerator(blockBreakPacket); Reflection.FieldAccessor blockBreakPosition = Reflection.getField(blockBreakPacket, TechHider.blockPosition, 0); Reflection.FieldAccessor blockBreakBlockData = Reflection.getField(blockBreakPacket, TechHider.iBlockData, 0); return (p, packet) -> { Object pos = blockBreakPosition.get(packet); - if(TechHider.bypass(p, TechHider.posToChunk(TechHider.blockPositionX.get(pos)), TechHider.posToChunk(TechHider.blockPositionZ.get(pos)))) + if(bypass.bypass(p, ProtocolUtils.posToChunk(TechHider.blockPositionX.get(pos)), ProtocolUtils.posToChunk(TechHider.blockPositionZ.get(pos)))) return packet; - if(ProtocolWrapper.impl.iBlockDataHidden(blockBreakBlockData.get(packet))){ + if(ProtocolWrapper.impl.iBlockDataHidden(obfuscate, blockBreakBlockData.get(packet))){ packet = blockBreakCloner.apply(packet); - blockBreakBlockData.set(packet, TechHider.obfuscateIBlockData); + blockBreakBlockData.set(packet, obfuscationTarget); } return packet; }; diff --git a/FightSystem_15/src/de/steamwar/fightsystem/utils/BlockIdWrapper15.java b/FightSystem_15/src/de/steamwar/fightsystem/utils/BlockIdWrapper15.java index 9ec0283..3a5452e 100644 --- a/FightSystem_15/src/de/steamwar/fightsystem/utils/BlockIdWrapper15.java +++ b/FightSystem_15/src/de/steamwar/fightsystem/utils/BlockIdWrapper15.java @@ -19,16 +19,13 @@ package de.steamwar.fightsystem.utils; -import de.steamwar.fightsystem.Config; import net.minecraft.server.v1_15_R1.*; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.craftbukkit.v1_15_R1.block.CraftBlock; -import java.util.HashSet; import java.util.Objects; -import java.util.Set; public class BlockIdWrapper15 implements BlockIdWrapper { @Override @@ -46,32 +43,6 @@ public class BlockIdWrapper15 implements BlockIdWrapper { cworld.getChunkProvider().flagDirty(pos); } - @Override - public Set getHiddenBlockIds() { - Set hiddenBlockIds = new HashSet<>(); - for(String tag : Config.HiddenBlocks){ - for(IBlockData data : IRegistry.BLOCK.get(new MinecraftKey(tag)).getStates().a()){ - hiddenBlockIds.add(net.minecraft.server.v1_15_R1.Block.getCombinedId(data)); - } - } - - if(Config.HiddenBlocks.contains("water")){ - Fluid water = FluidTypes.WATER.a(false); - for(IBlockData data : net.minecraft.server.v1_15_R1.Block.REGISTRY_ID){ - if(data.getFluid() == water){ - hiddenBlockIds.add(net.minecraft.server.v1_15_R1.Block.getCombinedId(data)); - } - } - } - - return hiddenBlockIds; - } - - @Override - public int getObfuscateWith() { - return net.minecraft.server.v1_15_R1.Block.getCombinedId(IRegistry.BLOCK.get(new MinecraftKey(Config.ObfuscateWith)).getBlockData()); - } - @Override public Object getPose(boolean sneaking) { return sneaking ? EntityPose.CROUCHING : EntityPose.STANDING; diff --git a/FightSystem_15/src/de/steamwar/techhider/BlockIds15.java b/FightSystem_15/src/de/steamwar/techhider/BlockIds15.java new file mode 100644 index 0000000..15e7c4d --- /dev/null +++ b/FightSystem_15/src/de/steamwar/techhider/BlockIds15.java @@ -0,0 +1,52 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ + +package de.steamwar.techhider; + +import net.minecraft.server.v1_15_R1.*; +import org.bukkit.Material; + +import java.util.HashSet; +import java.util.Set; + +public class BlockIds15 implements BlockIds { + @Override + public int materialToId(Material material) { + return Block.getCombinedId(IRegistry.BLOCK.get(new MinecraftKey(material.name().toLowerCase())).getBlockData()); + } + + @Override + public Set materialToAllIds(Material material) { + Set ids = new HashSet<>(); + for(IBlockData data : IRegistry.BLOCK.get(new MinecraftKey(material.name().toLowerCase())).getStates().a()) { + ids.add(Block.getCombinedId(data)); + } + + if(material == Material.WATER){ + Fluid water = FluidTypes.WATER.a(false); + for(IBlockData data : Block.REGISTRY_ID){ + if(data.getFluid() == water){ + ids.add(Block.getCombinedId(data)); + } + } + } + + return ids; + } +} diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java index 243aa24..23366db 100644 --- a/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java @@ -19,23 +19,16 @@ package de.steamwar.fightsystem.utils; -import de.steamwar.fightsystem.Config; import net.minecraft.core.BlockPosition; -import net.minecraft.core.IRegistry; -import net.minecraft.resources.MinecraftKey; import net.minecraft.server.level.WorldServer; import net.minecraft.world.entity.EntityPose; import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.level.material.Fluid; -import net.minecraft.world.level.material.FluidTypes; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; import org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock; -import java.util.HashSet; import java.util.Objects; -import java.util.Set; public class BlockIdWrapper18 implements BlockIdWrapper { @@ -54,32 +47,6 @@ public class BlockIdWrapper18 implements BlockIdWrapper { cworld.k().a(pos); } - @Override - public Set getHiddenBlockIds() { - Set hiddenBlockIds = new HashSet<>(); - for(String tag : Config.HiddenBlocks){ - for(IBlockData data : IRegistry.U.a(new MinecraftKey(tag)).m().a()){ - hiddenBlockIds.add(net.minecraft.world.level.block.Block.i(data)); - } - } - - if(Config.HiddenBlocks.contains("water")){ - Fluid water = FluidTypes.c.h(); - for(IBlockData data : net.minecraft.world.level.block.Block.o) { - if(data.o() == water) { - hiddenBlockIds.add(net.minecraft.world.level.block.Block.i(data)); - } - } - } - - return hiddenBlockIds; - } - - @Override - public int getObfuscateWith() { //ResourceLocation, DefaultedRegistry - return net.minecraft.world.level.block.Block.i(IRegistry.U.a(new MinecraftKey(Config.ObfuscateWith)).n()); - } - @Override public Object getPose(boolean sneaking) { return sneaking ? EntityPose.f : EntityPose.a; diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/ProtocolWrapper18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/ProtocolWrapper18.java index 52f2704..8938dab 100644 --- a/FightSystem_18/src/de/steamwar/fightsystem/utils/ProtocolWrapper18.java +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/ProtocolWrapper18.java @@ -22,22 +22,13 @@ package de.steamwar.fightsystem.utils; import com.comphenix.tinyprotocol.Reflection; import com.mojang.authlib.GameProfile; import com.mojang.datafixers.util.Pair; -import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.record.REntity; -import net.minecraft.core.IRegistry; -import net.minecraft.core.SectionPosition; -import net.minecraft.network.protocol.game.PacketPlayOutBlockBreak; import net.minecraft.world.entity.EntityTypes; -import net.minecraft.world.level.block.entity.TileEntityTypes; -import net.minecraft.world.level.block.state.IBlockData; import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; import java.util.Collections; import java.util.List; -import java.util.function.BiFunction; -import java.util.function.UnaryOperator; public class ProtocolWrapper18 implements ProtocolWrapper { @@ -83,48 +74,9 @@ public class ProtocolWrapper18 implements ProtocolWrapper { } } - private static final Reflection.FieldAccessor multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, SectionPosition.class, 0); - private static final Reflection.FieldAccessor multiBlockChangeBlocks = Reflection.getField(TechHider.multiBlockChangePacket, IBlockData[].class, 0); - private static final BiFunction, Object> iBlockDataArrayCloner = ProtocolAPI.arrayCloneGenerator(TechHider.iBlockData); - @Override - public Object multiBlockChangeHider(Player p, Object packet) { - Object chunkCoords = multiBlockChangeChunk.get(packet); - if(TechHider.bypass(p, TechHider.blockPositionX.get(chunkCoords), TechHider.blockPositionZ.get(chunkCoords))) - return packet; - - packet = TechHider.multiBlockChangeCloner.apply(packet); - multiBlockChangeBlocks.set(packet, iBlockDataArrayCloner.apply(multiBlockChangeBlocks.get(packet), block -> ProtocolWrapper.impl.iBlockDataHidden(block) ? TechHider.obfuscateIBlockData : block)); - return packet; - } - - private static final Reflection.FieldAccessor tileEntityType = Reflection.getField(TechHider.tileEntityDataPacket, TileEntityTypes.class, 0); - @Override - public boolean unfilteredTileEntityDataAction(Object packet) { - return tileEntityType.get(packet) != TileEntityTypes.h; - } - - @Override - public BiFunction blockBreakHiderGenerator(Class blockBreakPacket) { - return (p, packet) -> { - PacketPlayOutBlockBreak breakPacket = (PacketPlayOutBlockBreak) packet; - if(TechHider.bypass(p, TechHider.posToChunk(TechHider.blockPositionX.get(breakPacket.b())), TechHider.posToChunk(TechHider.blockPositionZ.get(breakPacket.b())))) - return packet; - - if(!ProtocolWrapper.impl.iBlockDataHidden(breakPacket.c())) - return packet; - - return new PacketPlayOutBlockBreak(breakPacket.b(), (IBlockData) TechHider.obfuscateIBlockData, breakPacket.d(), breakPacket.a()); - }; - } - private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(Fight.playerInfoDataClass, GameProfile.class, int.class, Fight.enumGamemode, Fight.iChatBaseComponent); @Override public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) { return playerInfoDataConstructor.invoke(profile, 0, mode, null); } - - @Override - public boolean iBlockDataHidden(Object iBlockData) { - return Config.HiddenBlocks.contains(IRegistry.U.b(((IBlockData) iBlockData).b()).a()); - } } diff --git a/FightSystem_18/src/de/steamwar/techhider/BlockIds18.java b/FightSystem_18/src/de/steamwar/techhider/BlockIds18.java new file mode 100644 index 0000000..13cf029 --- /dev/null +++ b/FightSystem_18/src/de/steamwar/techhider/BlockIds18.java @@ -0,0 +1,57 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ + +package de.steamwar.techhider; + +import net.minecraft.core.IRegistry; +import net.minecraft.resources.MinecraftKey; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.IBlockData; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.FluidTypes; +import org.bukkit.Material; + +import java.util.HashSet; +import java.util.Set; + +public class BlockIds18 implements BlockIds { + @Override + public int materialToId(Material material) { + return Block.i(IRegistry.U.a(new MinecraftKey(material.name().toLowerCase())).n()); + } + + @Override + public Set materialToAllIds(Material material) { + Set ids = new HashSet<>(); + for(IBlockData data : IRegistry.U.a(new MinecraftKey(material.name().toLowerCase())).m().a()){ + ids.add(Block.i(data)); + } + + if(material == Material.WATER){ + Fluid water = FluidTypes.c.h(); + for(IBlockData data : Block.o) { + if(data.o() == water) { + ids.add(Block.i(data)); + } + } + } + + return ids; + } +} diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/TechHider18.java b/FightSystem_18/src/de/steamwar/techhider/ChunkHider18.java similarity index 65% rename from FightSystem_18/src/de/steamwar/fightsystem/utils/TechHider18.java rename to FightSystem_18/src/de/steamwar/techhider/ChunkHider18.java index 98c1a28..53dc78f 100644 --- a/FightSystem_18/src/de/steamwar/fightsystem/utils/TechHider18.java +++ b/FightSystem_18/src/de/steamwar/techhider/ChunkHider18.java @@ -17,10 +17,9 @@ along with this program. If not, see . */ -package de.steamwar.fightsystem.utils; +package de.steamwar.techhider; import com.comphenix.tinyprotocol.Reflection; -import de.steamwar.fightsystem.Config; import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; import net.minecraft.core.IRegistry; @@ -34,19 +33,19 @@ import org.bukkit.entity.Player; import java.nio.ByteBuffer; import java.util.List; import java.util.Set; +import java.util.function.BiFunction; import java.util.function.IntFunction; import java.util.function.UnaryOperator; import java.util.stream.Collectors; -public class TechHider18 implements TechHider.ChunkHider { - +public class ChunkHider18 implements ChunkHider { @Override public Class mapChunkPacket() { return ClientboundLevelChunkWithLightPacket.class; } - private static final UnaryOperator chunkPacketCloner = ProtocolAPI.shallowCloneGenerator(ClientboundLevelChunkWithLightPacket.class); - private static final UnaryOperator chunkDataCloner = ProtocolAPI.shallowCloneGenerator(ClientboundLevelChunkPacketData.class); + private static final UnaryOperator chunkPacketCloner = ProtocolUtils.shallowCloneGenerator(ClientboundLevelChunkWithLightPacket.class); + private static final UnaryOperator chunkDataCloner = ProtocolUtils.shallowCloneGenerator(ClientboundLevelChunkPacketData.class); private static final Reflection.FieldAccessor chunkX = Reflection.getField(ClientboundLevelChunkWithLightPacket.class, int.class, 0); private static final Reflection.FieldAccessor chunkZ = Reflection.getField(ClientboundLevelChunkWithLightPacket.class, int.class, 1); @@ -57,32 +56,31 @@ public class TechHider18 implements TechHider.ChunkHider { public static final Class tileEntity = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$a"); protected static final Reflection.FieldAccessor entityType = Reflection.getField(tileEntity, TileEntityTypes.class, 0); - private final Set hiddenBlockIds = BlockIdWrapper.impl.getHiddenBlockIds(); - private final int obfuscateWith = BlockIdWrapper.impl.getObfuscateWith(); - @Override - public Object mapChunkHider(Player p, Object packet) { - if(TechHider.bypass(p, chunkX.get(packet), chunkZ.get(packet))) + public BiFunction chunkHiderGenerator(TechHider.BypassEvaluator bypass, int obfuscationTarget, Set obfuscate, Set hiddenBlockEntities) { + return (p, packet) -> { + if(bypass.bypass(p, chunkX.get(packet), chunkZ.get(packet))) + return packet; + + packet = chunkPacketCloner.apply(packet); + Object data = chunkDataCloner.apply(chunkData.get(packet)); + + tileEntities.set(data, ((List)tileEntities.get(data)).stream().filter(te -> tileEntityVisible(hiddenBlockEntities, te)).collect(Collectors.toList())); + + World world = p.getWorld(); + int sections = (world.getMaxHeight() - world.getMinHeight()) / 16; + dataField.set(data, dataHider(obfuscationTarget, obfuscate, dataField.get(data), sections)); + + chunkData.set(packet, data); return packet; - - packet = chunkPacketCloner.apply(packet); - Object data = chunkDataCloner.apply(chunkData.get(packet)); - - tileEntities.set(data, ((List)tileEntities.get(data)).stream().filter(this::tileEntityVisible).collect(Collectors.toList())); - - World world = p.getWorld(); - int sections = (world.getMaxHeight() - world.getMinHeight()) / 16; - dataField.set(data, dataHider(dataField.get(data), sections)); - - chunkData.set(packet, data); - return packet; + }; } - protected boolean tileEntityVisible(Object tile) { - return !Config.HiddenBlockEntities.contains(IRegistry.aa.b(entityType.get(tile)).a()); + protected boolean tileEntityVisible(Set hiddenBlockEntities, Object tile) { + return !hiddenBlockEntities.contains(IRegistry.aa.b(entityType.get(tile)).a()); } - private byte[] dataHider(byte[] data, int sections) { + private byte[] dataHider(int obfuscationTarget, Set obfuscate, byte[] data, int sections) { ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100); int i = 0; @@ -90,7 +88,7 @@ public class TechHider18 implements TechHider.ChunkHider { buffer.writeBytes(data, i, 2); // Block count i += 2; - i = containerWalker(data, buffer, i, 15, blockId -> hiddenBlockIds.contains(blockId) ? obfuscateWith : blockId, (curI, dataArrayLength, bitsPerBlock) -> { + i = containerWalker(data, buffer, i, 15, blockId -> obfuscate.contains(blockId) ? obfuscationTarget : blockId, (curI, dataArrayLength, bitsPerBlock) -> { if(bitsPerBlock < 15) { buffer.writeBytes(data, curI, dataArrayLength * 8); } else { @@ -100,8 +98,8 @@ public class TechHider18 implements TechHider.ChunkHider { SimpleBitStorage values = new SimpleBitStorage(bitsPerBlock, 4096, array); for (int pos = 0; pos < 4096; pos++) { - if (hiddenBlockIds.contains(values.a(pos))) { - values.b(pos, obfuscateWith); + if (obfuscate.contains(values.a(pos))) { + values.b(pos, obfuscationTarget); } } @@ -118,29 +116,29 @@ public class TechHider18 implements TechHider.ChunkHider { return outdata; } - private int containerWalker(byte[] data, ByteBuf buffer, int i, int globalPalette, IntFunction palette, Region.TriConsumer dataArray) { + private int containerWalker(byte[] data, ByteBuf buffer, int i, int globalPalette, IntFunction palette, TriConsumer dataArray) { byte bitsPerBlock = data[i++]; buffer.writeByte(bitsPerBlock); if(bitsPerBlock == 0) { - int paletteValue = TechHider.readVarInt(data, i); - i += TechHider.readVarIntLength(data, i); - buffer.writeBytes(TechHider.writeVarInt(palette.apply(paletteValue))); + int paletteValue = ProtocolUtils.readVarInt(data, i); + i += ProtocolUtils.readVarIntLength(data, i); + buffer.writeBytes(ProtocolUtils.writeVarInt(palette.apply(paletteValue))); }else if(bitsPerBlock < globalPalette) { - int paletteLength = TechHider.readVarInt(data, i); - int paletteLengthLength = TechHider.readVarIntLength(data, i); + int paletteLength = ProtocolUtils.readVarInt(data, i); + int paletteLengthLength = ProtocolUtils.readVarIntLength(data, i); buffer.writeBytes(data, i, paletteLengthLength); i += paletteLengthLength; for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++) { - int paletteValue = TechHider.readVarInt(data, i); - i += TechHider.readVarIntLength(data, i); - buffer.writeBytes(TechHider.writeVarInt(palette.apply(paletteValue))); + int paletteValue = ProtocolUtils.readVarInt(data, i); + i += ProtocolUtils.readVarIntLength(data, i); + buffer.writeBytes(ProtocolUtils.writeVarInt(palette.apply(paletteValue))); } } - int dataArrayLength = TechHider.readVarInt(data, i); - int dataArrayLengthLength = TechHider.readVarIntLength(data, i); + int dataArrayLength = ProtocolUtils.readVarInt(data, i); + int dataArrayLengthLength = ProtocolUtils.readVarIntLength(data, i); buffer.writeBytes(data, i, dataArrayLengthLength); i += dataArrayLengthLength; @@ -149,4 +147,8 @@ public class TechHider18 implements TechHider.ChunkHider { return i; } + + private interface TriConsumer { + void accept(X x, Y y, Z z); + } } diff --git a/FightSystem_18/src/de/steamwar/techhider/ProtocolWrapper18.java b/FightSystem_18/src/de/steamwar/techhider/ProtocolWrapper18.java new file mode 100644 index 0000000..7edbd8d --- /dev/null +++ b/FightSystem_18/src/de/steamwar/techhider/ProtocolWrapper18.java @@ -0,0 +1,77 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ + +package de.steamwar.techhider; + +import com.comphenix.tinyprotocol.Reflection; +import net.minecraft.core.IRegistry; +import net.minecraft.core.SectionPosition; +import net.minecraft.network.protocol.game.PacketPlayOutBlockBreak; +import net.minecraft.world.level.block.entity.TileEntityTypes; +import net.minecraft.world.level.block.state.IBlockData; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.Set; +import java.util.function.BiFunction; +import java.util.function.UnaryOperator; + +public class ProtocolWrapper18 implements ProtocolWrapper { + + private static final Reflection.FieldAccessor multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, SectionPosition.class, 0); + private static final Reflection.FieldAccessor multiBlockChangeBlocks = Reflection.getField(TechHider.multiBlockChangePacket, IBlockData[].class, 0); + private static final BiFunction, Object> iBlockDataArrayCloner = ProtocolUtils.arrayCloneGenerator(TechHider.iBlockData); + @Override + public BiFunction multiBlockChangeGenerator(Object obfuscationTarget, Set obfuscate, TechHider.BypassEvaluator bypass) { + return (p, packet) -> { + Object chunkCoords = multiBlockChangeChunk.get(packet); + if(bypass.bypass(p, TechHider.blockPositionX.get(chunkCoords), TechHider.blockPositionZ.get(chunkCoords))) + return packet; + + packet = TechHider.multiBlockChangeCloner.apply(packet); + multiBlockChangeBlocks.set(packet, iBlockDataArrayCloner.apply(multiBlockChangeBlocks.get(packet), block -> ProtocolWrapper.impl.iBlockDataHidden(obfuscate, block) ? obfuscationTarget : block)); + return packet; + }; + } + + private static final Reflection.FieldAccessor tileEntityType = Reflection.getField(TechHider.tileEntityDataPacket, TileEntityTypes.class, 0); + @Override + public boolean unfilteredTileEntityDataAction(Object packet) { + return tileEntityType.get(packet) != TileEntityTypes.h; + } + + @Override + public BiFunction blockBreakHiderGenerator(Class blockBreakPacket, Object obfuscationTarget, Set obfuscate, TechHider.BypassEvaluator bypass) { + return (p, packet) -> { + PacketPlayOutBlockBreak breakPacket = (PacketPlayOutBlockBreak) packet; + if(bypass.bypass(p, ProtocolUtils.posToChunk(TechHider.blockPositionX.get(breakPacket.b())), ProtocolUtils.posToChunk(TechHider.blockPositionZ.get(breakPacket.b())))) + return packet; + + if(!ProtocolWrapper.impl.iBlockDataHidden(obfuscate, breakPacket.c())) + return packet; + + return new PacketPlayOutBlockBreak(breakPacket.b(), (IBlockData) obfuscationTarget, breakPacket.d(), breakPacket.a()); + }; + } + + @Override + public boolean iBlockDataHidden(Set obfuscate, Object iBlockData) { + return obfuscate.contains(Material.getMaterial(IRegistry.U.b(((IBlockData) iBlockData).b()).a().toUpperCase())); + } +} diff --git a/FightSystem_19/src/de/steamwar/fightsystem/utils/BlockIdWrapper19.java b/FightSystem_19/src/de/steamwar/fightsystem/utils/BlockIdWrapper19.java index e7b861f..dd251ac 100644 --- a/FightSystem_19/src/de/steamwar/fightsystem/utils/BlockIdWrapper19.java +++ b/FightSystem_19/src/de/steamwar/fightsystem/utils/BlockIdWrapper19.java @@ -19,23 +19,16 @@ package de.steamwar.fightsystem.utils; -import de.steamwar.fightsystem.Config; import net.minecraft.core.BlockPosition; -import net.minecraft.core.IRegistry; -import net.minecraft.resources.MinecraftKey; import net.minecraft.server.level.WorldServer; import net.minecraft.world.entity.EntityPose; import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.level.material.Fluid; -import net.minecraft.world.level.material.FluidTypes; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; import org.bukkit.craftbukkit.v1_19_R1.block.CraftBlock; -import java.util.HashSet; import java.util.Objects; -import java.util.Set; public class BlockIdWrapper19 implements BlockIdWrapper { @@ -54,32 +47,6 @@ public class BlockIdWrapper19 implements BlockIdWrapper { cworld.k().a(pos); } - @Override - public Set getHiddenBlockIds() { - Set hiddenBlockIds = new HashSet<>(); - for(String tag : Config.HiddenBlocks){ - for(IBlockData data : IRegistry.V.a(new MinecraftKey(tag)).k().a()){ - hiddenBlockIds.add(net.minecraft.world.level.block.Block.i(data)); - } - } - - if(Config.HiddenBlocks.contains("water")){ - Fluid water = FluidTypes.c.h(); - for(IBlockData data : net.minecraft.world.level.block.Block.o) { - if(data.p() == water) { - hiddenBlockIds.add(net.minecraft.world.level.block.Block.i(data)); - } - } - } - - return hiddenBlockIds; - } - - @Override - public int getObfuscateWith() { //ResourceLocation, DefaultedRegistry - return net.minecraft.world.level.block.Block.i(IRegistry.V.a(new MinecraftKey(Config.ObfuscateWith)).m()); - } - @Override public Object getPose(boolean sneaking) { return sneaking ? EntityPose.f : EntityPose.a; diff --git a/FightSystem_19/src/de/steamwar/fightsystem/utils/ProtocolWrapper19.java b/FightSystem_19/src/de/steamwar/fightsystem/utils/ProtocolWrapper19.java index 4626f83..64a8692 100644 --- a/FightSystem_19/src/de/steamwar/fightsystem/utils/ProtocolWrapper19.java +++ b/FightSystem_19/src/de/steamwar/fightsystem/utils/ProtocolWrapper19.java @@ -22,21 +22,13 @@ package de.steamwar.fightsystem.utils; import com.comphenix.tinyprotocol.Reflection; import com.mojang.authlib.GameProfile; import com.mojang.datafixers.util.Pair; -import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.record.REntity; -import net.minecraft.core.IRegistry; -import net.minecraft.core.SectionPosition; import net.minecraft.world.entity.EntityTypes; -import net.minecraft.world.level.block.entity.TileEntityTypes; -import net.minecraft.world.level.block.state.IBlockData; import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; import java.util.Collections; import java.util.List; -import java.util.function.BiFunction; -import java.util.function.UnaryOperator; public class ProtocolWrapper19 implements ProtocolWrapper { @@ -82,39 +74,9 @@ public class ProtocolWrapper19 implements ProtocolWrapper { } } - private static final Reflection.FieldAccessor multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, SectionPosition.class, 0); - private static final Reflection.FieldAccessor multiBlockChangeBlocks = Reflection.getField(TechHider.multiBlockChangePacket, IBlockData[].class, 0); - private static final BiFunction, Object> iBlockDataArrayCloner = ProtocolAPI.arrayCloneGenerator(TechHider.iBlockData); - @Override - public Object multiBlockChangeHider(Player p, Object packet) { - Object chunkCoords = multiBlockChangeChunk.get(packet); - if(TechHider.bypass(p, TechHider.blockPositionX.get(chunkCoords), TechHider.blockPositionZ.get(chunkCoords))) - return packet; - - packet = TechHider.multiBlockChangeCloner.apply(packet); - multiBlockChangeBlocks.set(packet, iBlockDataArrayCloner.apply(multiBlockChangeBlocks.get(packet), block -> ProtocolWrapper.impl.iBlockDataHidden(block) ? TechHider.obfuscateIBlockData : block)); - return packet; - } - - private static final Reflection.FieldAccessor tileEntityType = Reflection.getField(TechHider.tileEntityDataPacket, TileEntityTypes.class, 0); - @Override - public boolean unfilteredTileEntityDataAction(Object packet) { - return tileEntityType.get(packet) != TileEntityTypes.h; - } - - @Override - public BiFunction blockBreakHiderGenerator(Class blockBreakPacket) { - return null; - } - private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(Fight.playerInfoDataClass, GameProfile.class, int.class, Fight.enumGamemode, Fight.iChatBaseComponent, Reflection.getClass("net.minecraft.world.entity.player.ProfilePublicKey$a")); @Override public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) { return playerInfoDataConstructor.invoke(profile, 0, mode, null, null); } - - @Override - public boolean iBlockDataHidden(Object iBlockData) { - return Config.HiddenBlocks.contains(IRegistry.V.b(((IBlockData) iBlockData).b()).a()); - } } diff --git a/FightSystem_19/src/de/steamwar/techhider/BlockIds19.java b/FightSystem_19/src/de/steamwar/techhider/BlockIds19.java new file mode 100644 index 0000000..e1e0b54 --- /dev/null +++ b/FightSystem_19/src/de/steamwar/techhider/BlockIds19.java @@ -0,0 +1,57 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ + +package de.steamwar.techhider; + +import net.minecraft.core.IRegistry; +import net.minecraft.resources.MinecraftKey; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.IBlockData; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.FluidTypes; +import org.bukkit.Material; + +import java.util.HashSet; +import java.util.Set; + +public class BlockIds19 implements BlockIds { + @Override + public int materialToId(Material material) { + return Block.i(IRegistry.V.a(new MinecraftKey(material.name().toLowerCase())).m()); + } + + @Override + public Set materialToAllIds(Material material) { + Set ids = new HashSet<>(); + for(IBlockData data : IRegistry.V.a(new MinecraftKey(material.name().toLowerCase())).k().a()){ + ids.add(Block.i(data)); + } + + if(material == Material.WATER){ + Fluid water = FluidTypes.c.h(); + for(IBlockData data : Block.o) { + if(data.p() == water) { + ids.add(Block.i(data)); + } + } + } + + return ids; + } +} diff --git a/FightSystem_19/src/de/steamwar/fightsystem/utils/TechHider19.java b/FightSystem_19/src/de/steamwar/techhider/ChunkHider19.java similarity index 75% rename from FightSystem_19/src/de/steamwar/fightsystem/utils/TechHider19.java rename to FightSystem_19/src/de/steamwar/techhider/ChunkHider19.java index eb61b75..0ebba1c 100644 --- a/FightSystem_19/src/de/steamwar/fightsystem/utils/TechHider19.java +++ b/FightSystem_19/src/de/steamwar/techhider/ChunkHider19.java @@ -17,15 +17,15 @@ along with this program. If not, see . */ -package de.steamwar.fightsystem.utils; +package de.steamwar.techhider; -import de.steamwar.fightsystem.Config; import net.minecraft.core.IRegistry; -public class TechHider19 extends TechHider18 { +import java.util.Set; +public class ChunkHider19 extends ChunkHider18 { @Override - protected boolean tileEntityVisible(Object tile) { - return !Config.HiddenBlockEntities.contains(IRegistry.ab.b(entityType.get(tile)).a()); + protected boolean tileEntityVisible(Set hiddenBlockEntities, Object tile) { + return !hiddenBlockEntities.contains(IRegistry.ab.b(entityType.get(tile)).a()); } } diff --git a/FightSystem_19/src/de/steamwar/techhider/ProtocolWrapper19.java b/FightSystem_19/src/de/steamwar/techhider/ProtocolWrapper19.java new file mode 100644 index 0000000..240f854 --- /dev/null +++ b/FightSystem_19/src/de/steamwar/techhider/ProtocolWrapper19.java @@ -0,0 +1,67 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ + +package de.steamwar.techhider; + +import com.comphenix.tinyprotocol.Reflection; +import net.minecraft.core.IRegistry; +import net.minecraft.core.SectionPosition; +import net.minecraft.world.level.block.entity.TileEntityTypes; +import net.minecraft.world.level.block.state.IBlockData; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.Set; +import java.util.function.BiFunction; +import java.util.function.UnaryOperator; + +public class ProtocolWrapper19 implements ProtocolWrapper { + + private static final Reflection.FieldAccessor multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, SectionPosition.class, 0); + private static final Reflection.FieldAccessor multiBlockChangeBlocks = Reflection.getField(TechHider.multiBlockChangePacket, IBlockData[].class, 0); + private static final BiFunction, Object> iBlockDataArrayCloner = ProtocolUtils.arrayCloneGenerator(TechHider.iBlockData); + @Override + public BiFunction multiBlockChangeGenerator(Object obfuscationTarget, Set obfuscate, TechHider.BypassEvaluator bypass) { + return (p, packet) -> { + Object chunkCoords = multiBlockChangeChunk.get(packet); + if(bypass.bypass(p, TechHider.blockPositionX.get(chunkCoords), TechHider.blockPositionZ.get(chunkCoords))) + return packet; + + packet = TechHider.multiBlockChangeCloner.apply(packet); + multiBlockChangeBlocks.set(packet, iBlockDataArrayCloner.apply(multiBlockChangeBlocks.get(packet), block -> ProtocolWrapper.impl.iBlockDataHidden(obfuscate, block) ? obfuscationTarget : block)); + return packet; + }; + } + + private static final Reflection.FieldAccessor tileEntityType = Reflection.getField(TechHider.tileEntityDataPacket, TileEntityTypes.class, 0); + @Override + public boolean unfilteredTileEntityDataAction(Object packet) { + return tileEntityType.get(packet) != TileEntityTypes.h; + } + + @Override + public BiFunction blockBreakHiderGenerator(Class blockBreakPacket, Object obfuscationTarget, Set obfuscate, TechHider.BypassEvaluator bypass) { + return null; + } + + @Override + public boolean iBlockDataHidden(Set obfuscate, Object iBlockData) { + return obfuscate.contains(Material.getMaterial(IRegistry.V.b(((IBlockData) iBlockData).b()).a().toUpperCase())); + } +} diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java index da5d971..bb8bae2 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java @@ -19,14 +19,9 @@ package de.steamwar.fightsystem.utils; -import de.steamwar.fightsystem.Config; -import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; -import java.util.HashSet; -import java.util.Set; - public class BlockIdWrapper8 implements BlockIdWrapper { @Override @SuppressWarnings("deprecation") @@ -40,22 +35,6 @@ public class BlockIdWrapper8 implements BlockIdWrapper { world.getBlockAt(x, y, z).setTypeIdAndData(blockState >> 4, (byte)(blockState & 0b1111), false); } - @Override - @SuppressWarnings("deprecation") - public Set getHiddenBlockIds() { - Set hiddenBlockIds = new HashSet<>(); - for(String tag : Config.HiddenBlocks){ - hiddenBlockIds.add(Material.matchMaterial(tag).getId() << 4); - } - return hiddenBlockIds; - } - - @Override - @SuppressWarnings("deprecation") - public int getObfuscateWith() { - return Material.matchMaterial(Config.ObfuscateWith).getId() << 4; - } - @Override public Object getPose(boolean sneaking) { return Byte.valueOf((byte)(sneaking ? 2 : 0)); diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/ProtocolWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/ProtocolWrapper8.java index 80c1135..c9cd67f 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/ProtocolWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/ProtocolWrapper8.java @@ -22,15 +22,9 @@ package de.steamwar.fightsystem.utils; import com.comphenix.tinyprotocol.Reflection; import com.mojang.authlib.GameProfile; import de.steamwar.core.Core; -import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.record.REntity; -import org.bukkit.Material; import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; - -import java.util.function.BiFunction; -import java.util.function.UnaryOperator; public class ProtocolWrapper8 implements ProtocolWrapper { @@ -106,53 +100,9 @@ public class ProtocolWrapper8 implements ProtocolWrapper { } } - private static final Class chunkCoordinateIntPair = Reflection.getClass("{nms}.ChunkCoordIntPair"); - private static final Reflection.FieldAccessor multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, chunkCoordinateIntPair, 0); - private static final Reflection.FieldAccessor chunkCoordinateX = Reflection.getField(chunkCoordinateIntPair, int.class, 0); - private static final Reflection.FieldAccessor chunkCoordinateZ = Reflection.getField(chunkCoordinateIntPair, int.class, 1); - private static final Class multiBlockChangeInfo = Reflection.getClass("{nms}.PacketPlayOutMultiBlockChange$MultiBlockChangeInfo"); - private static final Reflection.ConstructorInvoker multiBlockChangeInfoConstructor = Reflection.getConstructor(multiBlockChangeInfo, TechHider.multiBlockChangePacket, short.class, TechHider.iBlockData); - private static final BiFunction, Object> multiBlockChangeInfoArrayCloner = ProtocolAPI.arrayCloneGenerator(multiBlockChangeInfo); - private static final Reflection.FieldAccessor multiBlockChangeInfoBlock = Reflection.getField(multiBlockChangeInfo, TechHider.iBlockData, 0); - private static final Reflection.FieldAccessor multiBlockChangeInfoPos = Reflection.getField(multiBlockChangeInfo, short.class, 0); - private static final Class multiBlockChangeInfoArray = Reflection.getClass("[L{nms}.PacketPlayOutMultiBlockChange$MultiBlockChangeInfo;"); - private static final Reflection.FieldAccessor multiBlockChangeInfos = Reflection.getField(TechHider.multiBlockChangePacket, multiBlockChangeInfoArray, 0); - @Override - public Object multiBlockChangeHider(Player p, Object packet) { - Object chunkCoords = multiBlockChangeChunk.get(packet); - if(TechHider.bypass(p, chunkCoordinateX.get(chunkCoords), chunkCoordinateZ.get(chunkCoords))) - return packet; - - Object modpacket = TechHider.multiBlockChangeCloner.apply(packet); - multiBlockChangeInfos.set(modpacket, multiBlockChangeInfoArrayCloner.apply(multiBlockChangeInfos.get(modpacket), mbci -> { - if(ProtocolWrapper.impl.iBlockDataHidden(multiBlockChangeInfoBlock.get(mbci))) - return multiBlockChangeInfoConstructor.invoke(modpacket, multiBlockChangeInfoPos.get(mbci), TechHider.obfuscateIBlockData); - return mbci; - })); - return modpacket; - } - - private static final Reflection.FieldAccessor tileEntityDataAction = Reflection.getField(TechHider.tileEntityDataPacket, int.class, 0); - @Override - public boolean unfilteredTileEntityDataAction(Object packet) { - return tileEntityDataAction.get(packet) != 9; - } - - @Override - public BiFunction blockBreakHiderGenerator(Class blockBreakPacket) { - return null; - } - private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(Fight.playerInfoDataClass, Fight.playerInfoPacket, GameProfile.class, int.class, Fight.enumGamemode, Fight.iChatBaseComponent); @Override public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) { return playerInfoDataConstructor.invoke(packet, profile, 0, mode, null); } - - private static final Reflection.MethodInvoker getBlockByBlockData = Reflection.getTypedMethod(TechHider.iBlockData, null, TechHider.block); - private static final Reflection.MethodInvoker getMaterialByBlock = Reflection.getTypedMethod(TechHider.craftMagicNumbers, "getMaterial", Material.class, TechHider.block); - @Override - public boolean iBlockDataHidden(Object iBlockData) { - return Config.HiddenBlocks.contains(((Material) getMaterialByBlock.invoke(null, getBlockByBlockData.invoke(iBlockData))).name().toLowerCase()); - } } diff --git a/FightSystem_8/src/de/steamwar/techhider/BlockIds8.java b/FightSystem_8/src/de/steamwar/techhider/BlockIds8.java new file mode 100644 index 0000000..538e8db --- /dev/null +++ b/FightSystem_8/src/de/steamwar/techhider/BlockIds8.java @@ -0,0 +1,38 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ + +package de.steamwar.techhider; + +import org.bukkit.Material; + +import java.util.Collections; +import java.util.Set; + +public class BlockIds8 implements BlockIds { + @Override + @SuppressWarnings("deprecation") + public int materialToId(Material material) { + return material.getId() << 4; + } + + @Override + public Set materialToAllIds(Material material) { + return Collections.singleton(materialToId(material)); + } +} diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/TechHider8.java b/FightSystem_8/src/de/steamwar/techhider/ChunkHider8.java similarity index 75% rename from FightSystem_8/src/de/steamwar/fightsystem/utils/TechHider8.java rename to FightSystem_8/src/de/steamwar/techhider/ChunkHider8.java index d299c3d..3cc0d36 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/TechHider8.java +++ b/FightSystem_8/src/de/steamwar/techhider/ChunkHider8.java @@ -17,12 +17,15 @@ along with this program. If not, see . */ -package de.steamwar.fightsystem.utils; +package de.steamwar.techhider; import com.comphenix.tinyprotocol.Reflection; import org.bukkit.entity.Player; -public class TechHider8 implements TechHider.ChunkHider { +import java.util.Set; +import java.util.function.BiFunction; + +public class ChunkHider8 implements ChunkHider { protected static final Class mapChunkPacket = Reflection.getClass("{nms}.PacketPlayOutMapChunk"); @Override @@ -31,7 +34,7 @@ public class TechHider8 implements TechHider.ChunkHider { } @Override - public Object mapChunkHider(Player p, Object packet) { - return packet; + public BiFunction chunkHiderGenerator(TechHider.BypassEvaluator bypass, int obfuscationTarget, Set obfuscate, Set hiddenBlockEntities) { + return null; } } diff --git a/FightSystem_8/src/de/steamwar/techhider/ProtocolWrapper8.java b/FightSystem_8/src/de/steamwar/techhider/ProtocolWrapper8.java new file mode 100644 index 0000000..abc9e61 --- /dev/null +++ b/FightSystem_8/src/de/steamwar/techhider/ProtocolWrapper8.java @@ -0,0 +1,76 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ + +package de.steamwar.techhider; + +import com.comphenix.tinyprotocol.Reflection; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.Set; +import java.util.function.BiFunction; +import java.util.function.UnaryOperator; + +public class ProtocolWrapper8 implements ProtocolWrapper { + private static final Class chunkCoordinateIntPair = Reflection.getClass("{nms}.ChunkCoordIntPair"); + private static final Reflection.FieldAccessor multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, chunkCoordinateIntPair, 0); + private static final Reflection.FieldAccessor chunkCoordinateX = Reflection.getField(chunkCoordinateIntPair, int.class, 0); + private static final Reflection.FieldAccessor chunkCoordinateZ = Reflection.getField(chunkCoordinateIntPair, int.class, 1); + private static final Class multiBlockChangeInfo = Reflection.getClass("{nms}.PacketPlayOutMultiBlockChange$MultiBlockChangeInfo"); + private static final Reflection.ConstructorInvoker multiBlockChangeInfoConstructor = Reflection.getConstructor(multiBlockChangeInfo, TechHider.multiBlockChangePacket, short.class, TechHider.iBlockData); + private static final BiFunction, Object> multiBlockChangeInfoArrayCloner = ProtocolUtils.arrayCloneGenerator(multiBlockChangeInfo); + private static final Reflection.FieldAccessor multiBlockChangeInfoBlock = Reflection.getField(multiBlockChangeInfo, TechHider.iBlockData, 0); + private static final Reflection.FieldAccessor multiBlockChangeInfoPos = Reflection.getField(multiBlockChangeInfo, short.class, 0); + private static final Class multiBlockChangeInfoArray = Reflection.getClass("[L{nms}.PacketPlayOutMultiBlockChange$MultiBlockChangeInfo;"); + private static final Reflection.FieldAccessor multiBlockChangeInfos = Reflection.getField(TechHider.multiBlockChangePacket, multiBlockChangeInfoArray, 0); + @Override + public BiFunction multiBlockChangeGenerator(Object obfuscationTarget, Set obfuscate, TechHider.BypassEvaluator bypass) { + return (p, packet) -> { + Object chunkCoords = multiBlockChangeChunk.get(packet); + if(bypass.bypass(p, chunkCoordinateX.get(chunkCoords), chunkCoordinateZ.get(chunkCoords))) + return packet; + + Object modpacket = TechHider.multiBlockChangeCloner.apply(packet); + multiBlockChangeInfos.set(modpacket, multiBlockChangeInfoArrayCloner.apply(multiBlockChangeInfos.get(modpacket), mbci -> { + if(ProtocolWrapper.impl.iBlockDataHidden(obfuscate, multiBlockChangeInfoBlock.get(mbci))) + return multiBlockChangeInfoConstructor.invoke(modpacket, multiBlockChangeInfoPos.get(mbci), obfuscationTarget); + return mbci; + })); + return modpacket; + }; + } + + private static final Reflection.FieldAccessor tileEntityDataAction = Reflection.getField(TechHider.tileEntityDataPacket, int.class, 0); + @Override + public boolean unfilteredTileEntityDataAction(Object packet) { + return tileEntityDataAction.get(packet) != 9; + } + + @Override + public BiFunction blockBreakHiderGenerator(Class blockBreakPacket, Object obfuscationTarget, Set obfuscate, TechHider.BypassEvaluator bypass) { + return null; + } + + private static final Reflection.MethodInvoker getBlockByBlockData = Reflection.getTypedMethod(TechHider.iBlockData, null, TechHider.block); + private static final Reflection.MethodInvoker getMaterialByBlock = Reflection.getTypedMethod(TechHider.craftMagicNumbers, "getMaterial", Material.class, TechHider.block); + @Override + public boolean iBlockDataHidden(Set obfuscate, Object iBlockData) { + return obfuscate.contains((Material) getMaterialByBlock.invoke(null, getBlockByBlockData.invoke(iBlockData))); + } +} diff --git a/FightSystem_9/src/de/steamwar/fightsystem/utils/TechHider9.java b/FightSystem_9/src/de/steamwar/techhider/ChunkHider9.java similarity index 65% rename from FightSystem_9/src/de/steamwar/fightsystem/utils/TechHider9.java rename to FightSystem_9/src/de/steamwar/techhider/ChunkHider9.java index e9b0ba9..0272dd6 100644 --- a/FightSystem_9/src/de/steamwar/fightsystem/utils/TechHider9.java +++ b/FightSystem_9/src/de/steamwar/techhider/ChunkHider9.java @@ -17,10 +17,9 @@ along with this program. If not, see . */ -package de.steamwar.fightsystem.utils; +package de.steamwar.techhider; import com.comphenix.tinyprotocol.Reflection; -import de.steamwar.fightsystem.Config; import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; import org.bukkit.Bukkit; @@ -28,13 +27,14 @@ import org.bukkit.entity.Player; import java.util.List; import java.util.Set; +import java.util.function.BiFunction; import java.util.function.UnaryOperator; import java.util.logging.Level; import java.util.stream.Collectors; -public class TechHider9 extends TechHider8 { +public class ChunkHider9 extends ChunkHider8 { - private static final UnaryOperator mapChunkCloner = ProtocolAPI.shallowCloneGenerator(mapChunkPacket); + private static final UnaryOperator mapChunkCloner = ProtocolUtils.shallowCloneGenerator(mapChunkPacket); private static final Reflection.FieldAccessor mapChunkX = Reflection.getField(mapChunkPacket, int.class, 0); private static final Reflection.FieldAccessor mapChunkZ = Reflection.getField(mapChunkPacket, int.class, 1); @@ -45,26 +45,25 @@ public class TechHider9 extends TechHider8 { private static final Class nbtTagCompound = Reflection.getClass("{nms.nbt}.NBTTagCompound"); private static final Reflection.MethodInvoker nbtTagGetString = Reflection.getTypedMethod(nbtTagCompound, null, String.class, String.class); - protected final Set hiddenBlockIds = BlockIdWrapper.impl.getHiddenBlockIds(); - protected final int obfuscateWith = BlockIdWrapper.impl.getObfuscateWith(); - @Override - public Object mapChunkHider(Player p, Object packet) { - if(TechHider.bypass(p, mapChunkX.get(packet), mapChunkZ.get(packet))) + public BiFunction chunkHiderGenerator(TechHider.BypassEvaluator bypass, int obfuscationTarget, Set obfuscate, Set hiddenBlockEntities) { + return (p, packet) -> { + if(bypass.bypass(p, mapChunkX.get(packet), mapChunkZ.get(packet))) + return packet; + + packet = mapChunkCloner.apply(packet); + mapChunkBlockEntities.set(packet, ((List)mapChunkBlockEntities.get(packet)).stream().filter( + nbttag -> !hiddenBlockEntities.contains((String) nbtTagGetString.invoke(nbttag, "id")) + ).collect(Collectors.toList())); + + byte[] data = dataHider(obfuscationTarget, obfuscate, mapChunkData.get(packet), mapChunkBitMask.get(packet)); + mapChunkData.set(packet, data); + return packet; - - packet = mapChunkCloner.apply(packet); - mapChunkBlockEntities.set(packet, ((List)mapChunkBlockEntities.get(packet)).stream().filter( - nbttag -> !Config.HiddenBlockEntities.contains((String) nbtTagGetString.invoke(nbttag, "id")) - ).collect(Collectors.toList())); - - byte[] data = dataHider(mapChunkData.get(packet), mapChunkBitMask.get(packet)); - mapChunkData.set(packet, data); - - return packet; + }; } - protected byte[] dataHider(byte[] data, Integer primaryBitMask) { + protected byte[] dataHider(int obfuscationTarget, Set obfuscate, byte[] data, Integer primaryBitMask) { ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100); int i = 0; @@ -73,27 +72,27 @@ public class TechHider9 extends TechHider8 { buffer.writeByte(bitsPerBlock); if(bitsPerBlock != 13){ - int paletteLength = TechHider.readVarInt(data, i); - int paletteLengthLength = TechHider.readVarIntLength(data, i); + int paletteLength = ProtocolUtils.readVarInt(data, i); + int paletteLengthLength = ProtocolUtils.readVarIntLength(data, i); buffer.writeBytes(data, i, paletteLengthLength); i += paletteLengthLength; for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){ - int entry = TechHider.readVarInt(data, i); - i += TechHider.readVarIntLength(data, i); + int entry = ProtocolUtils.readVarInt(data, i); + i += ProtocolUtils.readVarIntLength(data, i); - if(hiddenBlockIds.contains(entry)){ - entry = obfuscateWith; + if(obfuscate.contains(entry)){ + entry = obfuscationTarget; } - buffer.writeBytes(TechHider.writeVarInt(entry)); + buffer.writeBytes(ProtocolUtils.writeVarInt(entry)); } }else{ buffer.writeByte(data[++i]); //Empty palette Bukkit.getLogger().log(Level.SEVERE, "Full chunk occured"); } - int dataArrayLength = TechHider.readVarInt(data, i); - int dataArrayLengthLength = TechHider.readVarIntLength(data, i); + int dataArrayLength = ProtocolUtils.readVarInt(data, i); + int dataArrayLengthLength = ProtocolUtils.readVarIntLength(data, i); buffer.writeBytes(data, i, dataArrayLength*8 + dataArrayLengthLength); i += dataArrayLengthLength; i += dataArrayLength * 8; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index b449484..2c940ed 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -48,6 +48,7 @@ public class FightSystem extends JavaPlugin { private Message message; private FightTeam lastWinner; private String lastWinreason; + private TechHiderWrapper techHider; @Override public void onLoad() { @@ -94,7 +95,7 @@ public class FightSystem extends JavaPlugin { new OneShotStateDependent(ArenaMode.All, FightState.PreSchemSetup, () -> Fight.playSound(SWSound.BLOCK_NOTE_PLING.getSound(), 100.0f, 2.0f)); new EnterHandler(); - new TechHider(); + techHider = new TechHiderWrapper(); new FightWorld(); new FightUI(); new FightStatistics(); @@ -192,6 +193,10 @@ public class FightSystem extends JavaPlugin { return plugin.lastWinreason; } + public static TechHiderWrapper getTechHider() { + return plugin.techHider; + } + public static void shutdown() { //Staggered kick to prevent lobby overloading if(Bukkit.getOnlinePlayers().isEmpty()){ diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java index e4acee0..c27fc2b 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java @@ -24,7 +24,7 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.utils.Message; import de.steamwar.fightsystem.utils.SWSound; -import de.steamwar.fightsystem.utils.TechHider; +import de.steamwar.techhider.ProtocolUtils; import net.md_5.bungee.api.ChatMessageType; import java.util.List; @@ -32,7 +32,7 @@ import java.util.List; public class EnternCountdown extends Countdown { private final FightPlayer fightPlayer; - private List chunkPos; + private List chunkPos; public EnternCountdown(FightPlayer fp) { super(Config.EnterStages.get(fp.getKit().getEnterStage()), new Message("ENTERN_COUNTDOWN"), SWSound.BLOCK_NOTE_PLING, false); @@ -43,12 +43,12 @@ public class EnternCountdown extends Countdown { @Override public void countdownFinished() { FightSystem.getMessage().sendPrefixless("ENTERN_ALLOWED", fightPlayer.getPlayer(), ChatMessageType.ACTION_BAR); - TechHider.reloadChunks(fightPlayer.getPlayer(), chunkPos, false); + FightSystem.getTechHider().reloadChunks(fightPlayer.getPlayer(), chunkPos, false); } @Override protected void prepareFinish() { - chunkPos = TechHider.prepareChunkReload(fightPlayer.getPlayer(), false); + chunkPos = FightSystem.getTechHider().prepareChunkReload(fightPlayer.getPlayer(), false); } @Override diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index e76b0fa..e79c740 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -35,6 +35,7 @@ import de.steamwar.fightsystem.utils.*; import de.steamwar.inventory.SWItem; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; +import de.steamwar.techhider.ProtocolUtils; import net.md_5.bungee.api.ChatMessageType; import org.bukkit.*; import org.bukkit.enchantments.Enchantment; @@ -244,7 +245,7 @@ public class FightTeam { } public void addMember(Player player, boolean silent) { - final List chunksToReload = TechHider.prepareChunkReload(player, false); + final List chunksToReload = FightSystem.getTechHider().prepareChunkReload(player, false); FightPlayer fightPlayer = new FightPlayer(player, this); players.put(player, fightPlayer); invited.remove(player); @@ -258,7 +259,7 @@ public class FightTeam { player.teleport(spawn); memberKit.loadToPlayer(player); GlobalRecorder.getInstance().playerJoins(player); - TechHider.reloadChunks(player, chunksToReload, false); + FightSystem.getTechHider().reloadChunks(player, chunksToReload, false); if(isLeaderless()) setLeader(fightPlayer, silent); @@ -270,7 +271,7 @@ public class FightTeam { FightPlayer fightPlayer = getFightPlayer(player); PersonalKitCreator.closeIfInKitCreator(player); - List chunksToReload = TechHider.prepareChunkReload(player, true); + List chunksToReload = FightSystem.getTechHider().prepareChunkReload(player, true); players.remove(player); team.removeEntry(player.getName()); @@ -285,7 +286,7 @@ public class FightTeam { player.getInventory().clear(); if(player.isOnline()){ - TechHider.reloadChunks(player, chunksToReload, true); + FightSystem.getTechHider().reloadChunks(player, chunksToReload, true); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java index 7cec941..202b4fd 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java @@ -20,6 +20,7 @@ package de.steamwar.fightsystem.listener; import com.comphenix.tinyprotocol.Reflection; +import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; @@ -48,6 +49,7 @@ import org.bukkit.event.player.*; import org.bukkit.inventory.ItemStack; import java.util.Random; +import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.Predicate; @@ -89,16 +91,19 @@ public class Recording implements Listener { } }.register(); new StateDependent(ArenaMode.AntiReplay, FightState.Ingame) { + private final BiFunction place = Recording.this::blockPlace; + private final BiFunction dig = Recording.this::blockDig; + @Override public void enable() { - ProtocolAPI.setIncomingHandler(blockPlacePacket, Recording.this::blockPlace); - ProtocolAPI.setIncomingHandler(blockDigPacket, Recording.this::blockDig); + TinyProtocol.instance.addFilter(blockPlacePacket, place); + TinyProtocol.instance.addFilter(blockDigPacket, dig); } @Override public void disable() { - ProtocolAPI.removeIncomingHandler(blockPlacePacket); - ProtocolAPI.removeIncomingHandler(blockDigPacket); + TinyProtocol.instance.removeFilter(blockPlacePacket, place); + TinyProtocol.instance.removeFilter(blockDigPacket, dig); } }.register(); new StateDependentTask(ArenaMode.AntiReplay, FightState.All, () -> { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index f94c3ed..65d6f6c 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -33,11 +33,13 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.utils.*; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.Team; +import de.steamwar.techhider.BlockIds; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.EntityType; import org.bukkit.scheduler.BukkitTask; @@ -46,6 +48,7 @@ import java.io.EOFException; import java.io.IOException; import java.util.*; import java.util.logging.Level; +import java.util.stream.Collectors; public class PacketProcessor { @@ -64,8 +67,8 @@ public class PacketProcessor { private final PacketSource source; private final BukkitTask task; private final LinkedList syncList = new LinkedList<>(); - private final Set hiddenBlockIds = BlockIdWrapper.impl.getHiddenBlockIds(); - private final int obfuscateWith = BlockIdWrapper.impl.getObfuscateWith(); + private final Set hiddenBlockIds = Config.HiddenBlocks.stream().map(Material::getMaterial).flatMap(m -> BlockIds.impl.materialToAllIds(m).stream()).collect(Collectors.toSet()); + private final int obfuscateWith = BlockIds.impl.materialToId(Material.getMaterial(Config.ObfuscateWith)); private final FreezeWorld freezer = new FreezeWorld(); private boolean rotateZ = false; @@ -345,7 +348,7 @@ public class PacketProcessor { if(!Config.ArenaRegion.in2dRegion(x, z)) return; //Outside of the arena - execSync(() -> BlockIdWrapper.impl.setBlock(Config.world, x, y, z, TechHider.ENABLED && hiddenBlockIds.contains(blockState) ? obfuscateWith : blockState)); + execSync(() -> BlockIdWrapper.impl.setBlock(Config.world, x, y, z, TechHiderWrapper.ENABLED && hiddenBlockIds.contains(blockState) ? obfuscateWith : blockState)); } private void particle() throws IOException { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/REntity.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/REntity.java index 2be8a48..6bb3831 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/REntity.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/REntity.java @@ -28,6 +28,7 @@ import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.listener.FightScoreboard; import de.steamwar.fightsystem.utils.*; import de.steamwar.sql.SteamwarUser; +import de.steamwar.techhider.ProtocolUtils; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; import org.bukkit.Material; @@ -65,7 +66,7 @@ public class REntity { if(entity.fireTick > 0) { entity.fireTick--; if(entity.fireTick == 0) { - ProtocolAPI.broadcastPacket(entity.getDataWatcherPacket(entityStatusWatcher, (byte)0)); + ProtocolUtils.broadcastPacket(entity.getDataWatcherPacket(entityStatusWatcher, (byte)0)); } } }); @@ -148,7 +149,7 @@ public class REntity { this.name = user.getUserName(); entities.put(internalId, this); - ProtocolAPI.broadcastPacket(getPlayerInfoPacket()); + ProtocolUtils.broadcastPacket(getPlayerInfoPacket()); team.addEntry(name); } @@ -160,7 +161,7 @@ public class REntity { this.uuid = new UUID(random.nextLong() & -61441L | 16384L, random.nextLong() & 4611686018427387903L | -9223372036854775808L); entities.put(internalId, this); - ProtocolAPI.broadcastPacket(getSpawnEntityPacket()); + ProtocolUtils.broadcastPacket(getSpawnEntityPacket()); } public void move(double locX, double locY, double locZ, float pitch, float yaw, byte headYaw){ @@ -168,15 +169,15 @@ public class REntity { this.locY = locY; this.locZ = locZ; if(entityType == EntityType.PLAYER && !playerSpawned) { - ProtocolAPI.broadcastPacket(getNamedSpawnPacket()); + ProtocolUtils.broadcastPacket(getNamedSpawnPacket()); playerSpawned = true; } this.yaw = (byte)((int)(yaw * 256.0F / 360.0F)); this.pitch = (byte)((int)(pitch * 256.0F / 360.0F)); this.headYaw = headYaw; - ProtocolAPI.broadcastPacket(getTeleportPacket()); - ProtocolAPI.broadcastPacket(getHeadRotationPacket()); + ProtocolUtils.broadcastPacket(getTeleportPacket()); + ProtocolUtils.broadcastPacket(getHeadRotationPacket()); } private static final Class animationPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutAnimation"); @@ -186,7 +187,7 @@ public class REntity { Object packet = Reflection.newInstance(animationPacket); animationEntity.set(packet, entityId); animationAnimation.set(packet, (int) animation); - ProtocolAPI.broadcastPacket(packet); + ProtocolUtils.broadcastPacket(packet); } private static final Class velocityPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityVelocity"); @@ -200,7 +201,7 @@ public class REntity { velocityX.set(packet, calcVelocity(dX)); velocityY.set(packet, calcVelocity(dY)); velocityZ.set(packet, calcVelocity(dZ)); - ProtocolAPI.broadcastPacket(packet); + ProtocolUtils.broadcastPacket(packet); } private static final Class statusPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityStatus"); @@ -210,12 +211,12 @@ public class REntity { Object packet = Reflection.newInstance(statusPacket); statusEntity.set(packet, entityId); statusStatus.set(packet, (byte) 2); - ProtocolAPI.broadcastPacket(packet); + ProtocolUtils.broadcastPacket(packet); } public void sneak(boolean sneaking) { sneaks = sneaking; - ProtocolAPI.broadcastPacket(getDataWatcherPacket(sneakingDataWatcher, BlockIdWrapper.impl.getPose(sneaking))); + ProtocolUtils.broadcastPacket(getDataWatcherPacket(sneakingDataWatcher, BlockIdWrapper.impl.getPose(sneaking))); } public void setOnFire(boolean perma) { @@ -225,14 +226,14 @@ public class REntity { fireTick = -1; } - ProtocolAPI.broadcastPacket(getDataWatcherPacket(entityStatusWatcher, (byte) 1)); + ProtocolUtils.broadcastPacket(getDataWatcherPacket(entityStatusWatcher, (byte) 1)); } public void setBowDrawn(boolean drawn, boolean offHand) { if(Core.getVersion() > 8){ - ProtocolAPI.broadcastPacket(getDataWatcherPacket(bowDrawnWatcher, (byte) ((drawn ? 1 : 0) + (offHand ? 2 : 0)))); + ProtocolUtils.broadcastPacket(getDataWatcherPacket(bowDrawnWatcher, (byte) ((drawn ? 1 : 0) + (offHand ? 2 : 0)))); }else{ - ProtocolAPI.broadcastPacket(getDataWatcherPacket(entityStatusWatcher, (byte)0x10)); + ProtocolUtils.broadcastPacket(getDataWatcherPacket(entityStatusWatcher, (byte)0x10)); } } @@ -242,7 +243,7 @@ public class REntity { stack.addUnsafeEnchantment(Enchantment.DURABILITY, 1); itemSlots.put(slot, stack); - ProtocolAPI.broadcastPacket(getEquipmentPacket(slot, stack)); + ProtocolUtils.broadcastPacket(getEquipmentPacket(slot, stack)); } public void die(){ @@ -261,13 +262,13 @@ public class REntity { private void broadcastDeath(){ if(entityType == EntityType.PLAYER){ - ProtocolAPI.broadcastPacket(Fight.playerInfoPacket(Fight.removePlayer, new GameProfile(uuid, name), Fight.creative)); + ProtocolUtils.broadcastPacket(Fight.playerInfoPacket(Fight.removePlayer, new GameProfile(uuid, name), Fight.creative)); team.removeEntry(name); } Object packet = Reflection.newInstance(destroyPacket); destroyEntities.set(packet, Core.getVersion() > 15 ? new IntArrayList(new int[]{entityId}) : new int[]{entityId}); - ProtocolAPI.broadcastPacket(packet); + ProtocolUtils.broadcastPacket(packet); } private int calcVelocity(double value) { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java index f9e65e7..74f7a46 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java @@ -24,16 +24,11 @@ import de.steamwar.fightsystem.FightSystem; import org.bukkit.World; import org.bukkit.block.Block; -import java.util.Set; - public interface BlockIdWrapper { BlockIdWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); int blockToId(Block block); void setBlock(World world, int x, int y, int z, int blockState); - Set getHiddenBlockIds(); - int getObfuscateWith(); - Object getPose(boolean sneaking); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/ProtocolWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/ProtocolWrapper.java index 1ca485a..c3eaa74 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/ProtocolWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/ProtocolWrapper.java @@ -23,9 +23,6 @@ import com.mojang.authlib.GameProfile; import de.steamwar.core.VersionDependent; import de.steamwar.fightsystem.FightSystem; import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; - -import java.util.function.BiFunction; public interface ProtocolWrapper { ProtocolWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); @@ -34,13 +31,6 @@ public interface ProtocolWrapper { void setSpawnPacketType(Object packet, EntityType type); - Object multiBlockChangeHider(Player p, Object packet); - - boolean unfilteredTileEntityDataAction(Object packet); - - BiFunction blockBreakHiderGenerator(Class blockBreakPacket); - Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode); - boolean iBlockDataHidden(Object iBlockData); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java deleted file mode 100644 index 0cdb6fa..0000000 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java +++ /dev/null @@ -1,247 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.fightsystem.utils; - -import com.comphenix.tinyprotocol.Reflection; -import com.google.common.primitives.Bytes; -import de.steamwar.core.Core; -import de.steamwar.core.CraftbukkitWrapper; -import de.steamwar.core.VersionDependent; -import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependent; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Material; -import org.bukkit.entity.Player; - -import java.util.*; -import java.util.function.BiFunction; -import java.util.function.Function; -import java.util.function.UnaryOperator; - -public class TechHider extends StateDependent { - - public static final Class blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); - private static final Class baseBlockPosition = Reflection.getClass("{nms.core}.BaseBlockPosition"); - public static final Reflection.FieldAccessor blockPositionX = Reflection.getField(baseBlockPosition, int.class, 0); - public static final Reflection.FieldAccessor blockPositionZ = Reflection.getField(baseBlockPosition, int.class, 2); - - public static final Class iBlockData = Reflection.getClass("{nms.world.level.block.state}.IBlockData"); - public static final Class block = Reflection.getClass("{nms.world.level.block}.Block"); - private static final Reflection.MethodInvoker getBlockDataByBlock = Reflection.getTypedMethod(block, null, iBlockData); - - public static final Class craftMagicNumbers = Reflection.getClass("{obc}.util.CraftMagicNumbers"); - private static final Reflection.MethodInvoker getBlockByMaterial = Reflection.getTypedMethod(craftMagicNumbers, "getBlock", block, Material.class); - - public static final boolean ENABLED = !Config.OnlyPublicSchematics && !Config.test() && Config.TechhiderActive; - - public static final Object obfuscateIBlockData = getBlockDataByBlock.invoke(getBlockByMaterial.invoke(null, Material.getMaterial(Config.ObfuscateWith.toUpperCase()))); - private final Map, BiFunction> techhiders = new HashMap<>(); - - public interface ChunkHider { - Class mapChunkPacket(); - Object mapChunkHider(Player p, Object packet); - } - - public TechHider(){ - super(ENABLED, FightState.Schem); - - techhiders.put(blockActionPacket, this::blockActionHider); - techhiders.put(blockChangePacket, this::blockChangeHider); - techhiders.put(tileEntityDataPacket, this::tileEntityDataHider); - techhiders.put(multiBlockChangePacket, ProtocolWrapper.impl::multiBlockChangeHider); - - ChunkHider chunkHider = VersionDependent.getVersionImpl(FightSystem.getPlugin()); - techhiders.put(chunkHider.mapChunkPacket(), chunkHider::mapChunkHider); - - if(Core.getVersion() > 12 && Core.getVersion() < 19) { - Class blockBreakClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutBlockBreak"); - techhiders.put(blockBreakClass, ProtocolWrapper.impl.blockBreakHiderGenerator(blockBreakClass)); - } - - if(Core.getVersion() > 8){ - ProtocolAPI.setIncomingHandler(Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem"), (p, packet) -> p.getGameMode() == GameMode.SPECTATOR ? null : packet); - } - ProtocolAPI.setIncomingHandler(Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity"), (p, packet) -> p.getGameMode() == GameMode.SPECTATOR ? null : packet); - - register(); - } - - @Override - public void enable() { - techhiders.forEach(ProtocolAPI::setOutgoingHandler); - } - - @Override - public void disable() { - techhiders.keySet().forEach(ProtocolAPI::removeOutgoingHandler); - } - - public static final Class multiBlockChangePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutMultiBlockChange"); - public static final UnaryOperator multiBlockChangeCloner = ProtocolAPI.shallowCloneGenerator(TechHider.multiBlockChangePacket); - - private static final Class blockChangePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutBlockChange"); - private static final Function blockChangeCloner = ProtocolAPI.shallowCloneGenerator(blockChangePacket); - private static final Reflection.FieldAccessor blockChangePosition = Reflection.getField(blockChangePacket, blockPosition, 0); - private static final Reflection.FieldAccessor blockChangeBlockData = Reflection.getField(blockChangePacket, iBlockData, 0); - private Object blockChangeHider(Player p, Object packet) { - Object pos = blockChangePosition.get(packet); - if(bypass(p, posToChunk(blockPositionX.get(pos)), posToChunk(blockPositionZ.get(pos)))) - return packet; - - if(ProtocolWrapper.impl.iBlockDataHidden(blockChangeBlockData.get(packet))) { - packet = blockChangeCloner.apply(packet); - blockChangeBlockData.set(packet, obfuscateIBlockData); - } - return packet; - } - - private static final Class blockActionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutBlockAction"); - private static final Reflection.FieldAccessor blockActionPosition = Reflection.getField(blockActionPacket, blockPosition, 0); - private Object blockActionHider(Player p, Object packet) { - Object pos = blockActionPosition.get(packet); - if(bypass(p, posToChunk(blockPositionX.get(pos)), posToChunk(blockPositionZ.get(pos)))) - return packet; - return null; - } - - public static final Class tileEntityDataPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutTileEntityData"); - private static final Reflection.FieldAccessor tileEntityDataPosition = Reflection.getField(tileEntityDataPacket, blockPosition, 0); - private Object tileEntityDataHider(Player p, Object packet) { - Object pos = tileEntityDataPosition.get(packet); - if(bypass(p, posToChunk(blockPositionX.get(pos)), posToChunk(blockPositionZ.get(pos)))) - return packet; - - if(ProtocolWrapper.impl.unfilteredTileEntityDataAction(packet)) - return packet; - return null; - } - - public static List prepareChunkReload(Player p, boolean hide){ - if(!ENABLED) - return Collections.emptyList(); - List chunksToReload = new ArrayList<>(); - Config.ArenaRegion.forEachChunk((x, z) -> { - if(bypass(p, x, z) == hide) - chunksToReload.add(new ChunkPos(x, z)); - }); - return chunksToReload; - } - - public static void reloadChunks(Player p, List chunksToReload, boolean hide){ - if(!ENABLED || !FightState.Schem.contains(FightState.getFightState())) - return; - Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { - for(ChunkPos chunk : chunksToReload){ - if(bypass(p, chunk.x(), chunk.z()) != hide) - CraftbukkitWrapper.impl.sendChunk(p, chunk.x(), chunk.z()); - } - }, 40); - } - - public static boolean bypass(Player p, int chunkX, int chunkZ){ - if(Config.isReferee(p)) - return true; - - FightTeam ft = Fight.getPlayerTeam(p); - if(ft == null){ - return Config.ArenaRegion.chunkOutside(chunkX, chunkZ); - }else if(ft.isBlue()){ - return ft.canPlayerEntern(p) || Config.RedExtendRegion.chunkOutside(chunkX, chunkZ); - }else{ - return ft.canPlayerEntern(p) || Config.BlueExtendRegion.chunkOutside(chunkX, chunkZ); - } - } - - public static int posToChunk(int c){ - int chunk = c / 16; - if(c<0) - chunk--; - return chunk; - } - - static int readVarInt(byte[] array, int startPos) { - int numRead = 0; - int result = 0; - byte read; - do { - read = array[startPos + numRead]; - int value = (read & 0b01111111); - result |= (value << (7 * numRead)); - - numRead++; - if (numRead > 5) { - break; - } - } while ((read & 0b10000000) != 0); - - return result; - } - - static int readVarIntLength(byte[] array, int startPos) { - int numRead = 0; - byte read; - do { - read = array[startPos + numRead]; - numRead++; - if (numRead > 5) { - break; - } - } while ((read & 0b10000000) != 0); - - return numRead; - } - - static byte[] writeVarInt(int value) { - List buffer = new ArrayList<>(5); - do { - byte temp = (byte)(value & 0b01111111); - // Note: >>> means that the sign bit is shifted with the rest of the number rather than being left alone - value >>>= 7; - if (value != 0) { - temp |= 0b10000000; - } - buffer.add(temp); - } while (value != 0); - return Bytes.toArray(buffer); - } - - public static class ChunkPos{ - final int x; - final int z; - - ChunkPos(int x, int z){ - this.x = x; - this.z = z; - } - - final int x(){ - return x; - } - - final int z(){ - return z; - } - } -} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java new file mode 100644 index 0000000..35548b1 --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHiderWrapper.java @@ -0,0 +1,98 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ + +package de.steamwar.fightsystem.utils; + +import de.steamwar.core.CraftbukkitWrapper; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; +import de.steamwar.techhider.ProtocolUtils; +import de.steamwar.techhider.TechHider; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +public class TechHiderWrapper extends StateDependent { + + public static final boolean ENABLED = !Config.OnlyPublicSchematics && !Config.test() && Config.TechhiderActive; + private final TechHider techHider; + + public TechHiderWrapper() { + super(ENABLED, FightState.Schem); + techHider = new TechHider(this::bypass, Material.getMaterial(Config.ObfuscateWith), Config.HiddenBlocks.stream().map(Material::getMaterial).collect(Collectors.toSet()), Config.HiddenBlockEntities); + register(); + } + + @Override + public void enable() { + techHider.enable(); + } + + @Override + public void disable() { + techHider.disable(); + } + + public List prepareChunkReload(Player p, boolean hide) { + if(!ENABLED) + return Collections.emptyList(); + + List chunksToReload = new ArrayList<>(); + Config.ArenaRegion.forEachChunk((x, z) -> { + if(bypass(p, x, z) == hide) + chunksToReload.add(new ProtocolUtils.ChunkPos(x, z)); + }); + return chunksToReload; + } + + public void reloadChunks(Player p, List chunksToReload, boolean hide) { + if(!ENABLED || !FightState.Schem.contains(FightState.getFightState())) + return; + + Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { + for(ProtocolUtils.ChunkPos chunk : chunksToReload){ + if(bypass(p, chunk.x(), chunk.z()) != hide) + CraftbukkitWrapper.impl.sendChunk(p, chunk.x(), chunk.z()); + } + }, 40); + } + + private boolean bypass(Player p, int chunkX, int chunkZ){ + if(Config.isReferee(p)) + return true; + + FightTeam ft = Fight.getPlayerTeam(p); + if(ft == null){ + return Config.ArenaRegion.chunkOutside(chunkX, chunkZ); + }else if(ft.isBlue()){ + return ft.canPlayerEntern(p) || Config.RedExtendRegion.chunkOutside(chunkX, chunkZ); + }else{ + return ft.canPlayerEntern(p) || Config.BlueExtendRegion.chunkOutside(chunkX, chunkZ); + } + } +} diff --git a/FightSystem_Core/src/de/steamwar/techhider/BlockIds.java b/FightSystem_Core/src/de/steamwar/techhider/BlockIds.java new file mode 100644 index 0000000..1ab7353 --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/techhider/BlockIds.java @@ -0,0 +1,33 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ + +package de.steamwar.techhider; + +import de.steamwar.core.VersionDependent; +import de.steamwar.fightsystem.FightSystem; +import org.bukkit.Material; + +import java.util.Set; + +public interface BlockIds { + BlockIds impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); + + int materialToId(Material material); + Set materialToAllIds(Material material); +} diff --git a/FightSystem_Core/src/de/steamwar/techhider/ChunkHider.java b/FightSystem_Core/src/de/steamwar/techhider/ChunkHider.java new file mode 100644 index 0000000..0711f37 --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/techhider/ChunkHider.java @@ -0,0 +1,34 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2022 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ + +package de.steamwar.techhider; + +import de.steamwar.core.VersionDependent; +import de.steamwar.fightsystem.FightSystem; +import org.bukkit.entity.Player; + +import java.util.Set; +import java.util.function.BiFunction; + +public interface ChunkHider { + ChunkHider impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); + + Class mapChunkPacket(); + BiFunction chunkHiderGenerator(TechHider.BypassEvaluator bypass, int obfuscationTarget, Set obfuscate, Set hiddenBlockEntities); +} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/ProtocolAPI.java b/FightSystem_Core/src/de/steamwar/techhider/ProtocolUtils.java similarity index 62% rename from FightSystem_Core/src/de/steamwar/fightsystem/utils/ProtocolAPI.java rename to FightSystem_Core/src/de/steamwar/techhider/ProtocolUtils.java index a66f932..1fc9e31 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/ProtocolAPI.java +++ b/FightSystem_Core/src/de/steamwar/techhider/ProtocolUtils.java @@ -1,7 +1,7 @@ /* This file is a part of the SteamWar software. - Copyright (C) 2021 SteamWar.de-Serverteam + Copyright (C) 2022 SteamWar.de-Serverteam This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by @@ -17,60 +17,24 @@ along with this program. If not, see . */ -package de.steamwar.fightsystem.utils; +package de.steamwar.techhider; import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; +import com.google.common.primitives.Bytes; import org.bukkit.Bukkit; -import org.bukkit.entity.Player; import java.lang.reflect.Array; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.UnaryOperator; -public class ProtocolAPI { - private ProtocolAPI() {} - - private static final Map, BiFunction> outgoingHandler = new HashMap<>(); - private static final Map, BiFunction> incomingHandler = new HashMap<>(); - - static { - TinyProtocol.instance.setOutFilter((receiver, channel, packet) -> { - BiFunction handler = outgoingHandler.get(packet.getClass()); - if(handler == null) - return packet; - return handler.apply(receiver, packet); - }); - TinyProtocol.instance.setInFilter((sender, channel, packet) -> { - BiFunction handler = incomingHandler.get(packet.getClass()); - if(handler == null) - return packet; - return handler.apply(sender, packet); - }); - } - - public static void setOutgoingHandler(Class packetClass, BiFunction handler) { - outgoingHandler.put(packetClass, handler); - } - - public static void removeOutgoingHandler(Class packetClass) { - outgoingHandler.remove(packetClass); - } - - public static void setIncomingHandler(Class packetClass, BiFunction handler) { - incomingHandler.put(packetClass, handler); - } - - public static void removeIncomingHandler(Class packetClass) { - incomingHandler.remove(packetClass); - } +public class ProtocolUtils { + private ProtocolUtils() {} public static void broadcastPacket(Object packet) { Bukkit.getOnlinePlayers().stream().map(TinyProtocol.instance::getChannel).filter(TinyProtocol.instance::hasInjected).forEach(channel -> TinyProtocol.instance.sendPacket(channel, packet)); @@ -126,4 +90,75 @@ public class ProtocolAPI { }; } + + public static int posToChunk(int c){ + int chunk = c / 16; + if(c<0) + chunk--; + return chunk; + } + + public static int readVarInt(byte[] array, int startPos) { + int numRead = 0; + int result = 0; + byte read; + do { + read = array[startPos + numRead]; + int value = (read & 0b01111111); + result |= (value << (7 * numRead)); + + numRead++; + if (numRead > 5) { + break; + } + } while ((read & 0b10000000) != 0); + + return result; + } + + public static int readVarIntLength(byte[] array, int startPos) { + int numRead = 0; + byte read; + do { + read = array[startPos + numRead]; + numRead++; + if (numRead > 5) { + break; + } + } while ((read & 0b10000000) != 0); + + return numRead; + } + + public static byte[] writeVarInt(int value) { + List buffer = new ArrayList<>(5); + do { + byte temp = (byte)(value & 0b01111111); + // Note: >>> means that the sign bit is shifted with the rest of the number rather than being left alone + value >>>= 7; + if (value != 0) { + temp |= 0b10000000; + } + buffer.add(temp); + } while (value != 0); + return Bytes.toArray(buffer); + } + + public static class ChunkPos{ + final int x; + final int z; + + public ChunkPos(int x, int z){ + this.x = x; + this.z = z; + } + + public final int x(){ + return x; + } + + public final int z(){ + return z; + } + } } diff --git a/FightSystem_Core/src/de/steamwar/techhider/ProtocolWrapper.java b/FightSystem_Core/src/de/steamwar/techhider/ProtocolWrapper.java new file mode 100644 index 0000000..49da27d --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/techhider/ProtocolWrapper.java @@ -0,0 +1,41 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ + +package de.steamwar.techhider; + +import de.steamwar.core.VersionDependent; +import de.steamwar.fightsystem.FightSystem; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.Set; +import java.util.function.BiFunction; + +public interface ProtocolWrapper { + ProtocolWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); + + + boolean unfilteredTileEntityDataAction(Object packet); + + BiFunction blockBreakHiderGenerator(Class blockBreakPacket, Object obfuscationTarget, Set obfuscate, TechHider.BypassEvaluator bypass); + + BiFunction multiBlockChangeGenerator(Object obfuscationTarget, Set obfuscate, TechHider.BypassEvaluator bypass); + + boolean iBlockDataHidden(Set obfuscate, Object iBlockData); +} diff --git a/FightSystem_Core/src/de/steamwar/techhider/TechHider.java b/FightSystem_Core/src/de/steamwar/techhider/TechHider.java new file mode 100644 index 0000000..7f089e0 --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/techhider/TechHider.java @@ -0,0 +1,128 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ + +package de.steamwar.techhider; + +import com.comphenix.tinyprotocol.Reflection; +import com.comphenix.tinyprotocol.TinyProtocol; +import de.steamwar.core.Core; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.*; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.function.UnaryOperator; +import java.util.stream.Collectors; + +public class TechHider { + + public static final Class blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); + private static final Class baseBlockPosition = Reflection.getClass("{nms.core}.BaseBlockPosition"); + public static final Reflection.FieldAccessor blockPositionX = Reflection.getField(baseBlockPosition, int.class, 0); + public static final Reflection.FieldAccessor blockPositionZ = Reflection.getField(baseBlockPosition, int.class, 2); + + public static final Class iBlockData = Reflection.getClass("{nms.world.level.block.state}.IBlockData"); + public static final Class block = Reflection.getClass("{nms.world.level.block}.Block"); + private static final Reflection.MethodInvoker getBlockDataByBlock = Reflection.getTypedMethod(block, null, iBlockData); + + public static final Class craftMagicNumbers = Reflection.getClass("{obc}.util.CraftMagicNumbers"); + private static final Reflection.MethodInvoker getBlockByMaterial = Reflection.getTypedMethod(craftMagicNumbers, "getBlock", block, Material.class); + + private final Map, BiFunction> techhiders = new HashMap<>(); + private final BypassEvaluator bypass; + private final Object obfuscationTarget; + private final Set obfuscate; + + public TechHider(BypassEvaluator bypass, Material obfuscationTarget, Set obfuscate, Set hiddenBlockEntities) { + this.bypass = bypass; + this.obfuscate = obfuscate; + this.obfuscationTarget = getBlockDataByBlock.invoke(getBlockByMaterial.invoke(null, obfuscationTarget)); + + techhiders.put(blockActionPacket, this::blockActionHider); + techhiders.put(blockChangePacket, this::blockChangeHider); + techhiders.put(tileEntityDataPacket, this::tileEntityDataHider); + techhiders.put(multiBlockChangePacket,ProtocolWrapper.impl.multiBlockChangeGenerator(obfuscationTarget, obfuscate, bypass)); + techhiders.put(ChunkHider.impl.mapChunkPacket(), ChunkHider.impl.chunkHiderGenerator(bypass, BlockIds.impl.materialToId(obfuscationTarget), obfuscate.stream().flatMap(m -> BlockIds.impl.materialToAllIds(m).stream()).collect(Collectors.toSet()), hiddenBlockEntities)); + + if(Core.getVersion() > 12 && Core.getVersion() < 19) { + Class blockBreakClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutBlockBreak"); + techhiders.put(blockBreakClass, ProtocolWrapper.impl.blockBreakHiderGenerator(blockBreakClass, obfuscationTarget, obfuscate, bypass)); + } + + if(Core.getVersion() > 8){ + techhiders.put(Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem"), (p, packet) -> p.getGameMode() == GameMode.SPECTATOR ? null : packet); + } + techhiders.put(Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity"), (p, packet) -> p.getGameMode() == GameMode.SPECTATOR ? null : packet); + + } + + public void enable() { + techhiders.forEach(TinyProtocol.instance::addFilter); + } + + public void disable() { + techhiders.forEach(TinyProtocol.instance::removeFilter); + } + + public static final Class multiBlockChangePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutMultiBlockChange"); + public static final UnaryOperator multiBlockChangeCloner = ProtocolUtils.shallowCloneGenerator(TechHider.multiBlockChangePacket); + + private static final Class blockChangePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutBlockChange"); + private static final Function blockChangeCloner = ProtocolUtils.shallowCloneGenerator(blockChangePacket); + private static final Reflection.FieldAccessor blockChangePosition = Reflection.getField(blockChangePacket, blockPosition, 0); + private static final Reflection.FieldAccessor blockChangeBlockData = Reflection.getField(blockChangePacket, iBlockData, 0); + private Object blockChangeHider(Player p, Object packet) { + Object pos = blockChangePosition.get(packet); + if(bypass.bypass(p, ProtocolUtils.posToChunk(blockPositionX.get(pos)), ProtocolUtils.posToChunk(blockPositionZ.get(pos)))) + return packet; + + if(ProtocolWrapper.impl.iBlockDataHidden(obfuscate, blockChangeBlockData.get(packet))) { + packet = blockChangeCloner.apply(packet); + blockChangeBlockData.set(packet, obfuscationTarget); + } + return packet; + } + + private static final Class blockActionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutBlockAction"); + private static final Reflection.FieldAccessor blockActionPosition = Reflection.getField(blockActionPacket, blockPosition, 0); + private Object blockActionHider(Player p, Object packet) { + Object pos = blockActionPosition.get(packet); + if(bypass.bypass(p, ProtocolUtils.posToChunk(blockPositionX.get(pos)), ProtocolUtils.posToChunk(blockPositionZ.get(pos)))) + return packet; + return null; + } + + public static final Class tileEntityDataPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutTileEntityData"); + private static final Reflection.FieldAccessor tileEntityDataPosition = Reflection.getField(tileEntityDataPacket, blockPosition, 0); + private Object tileEntityDataHider(Player p, Object packet) { + Object pos = tileEntityDataPosition.get(packet); + if(bypass.bypass(p, ProtocolUtils.posToChunk(blockPositionX.get(pos)), ProtocolUtils.posToChunk(blockPositionZ.get(pos)))) + return packet; + + if(ProtocolWrapper.impl.unfilteredTileEntityDataAction(packet)) + return packet; + return null; + } + + public interface BypassEvaluator { + boolean bypass(Player p, int chunkX, int chunkZ); + } +} -- 2.39.2 From 68e47e765717414080b5f62c7cf3acccdc5a06ce Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 16 Jul 2022 10:24:30 +0200 Subject: [PATCH 2/3] Use SpigotCore Techhider Signed-off-by: Lixfel --- .../src/de/steamwar/techhider/BlockIds14.java | 52 ------ .../de/steamwar/techhider/ChunkHider14.java | 141 --------------- .../steamwar/techhider/ProtocolWrapper14.java | 50 ------ .../src/de/steamwar/techhider/BlockIds15.java | 52 ------ .../src/de/steamwar/techhider/BlockIds18.java | 57 ------ .../de/steamwar/techhider/ChunkHider18.java | 154 ---------------- .../steamwar/techhider/ProtocolWrapper18.java | 77 -------- .../src/de/steamwar/techhider/BlockIds19.java | 57 ------ .../de/steamwar/techhider/ChunkHider19.java | 31 ---- .../steamwar/techhider/ProtocolWrapper19.java | 67 ------- .../src/de/steamwar/techhider/BlockIds8.java | 38 ---- .../de/steamwar/techhider/ChunkHider8.java | 40 ----- .../steamwar/techhider/ProtocolWrapper8.java | 76 -------- .../de/steamwar/techhider/ChunkHider9.java | 108 ------------ .../src/de/steamwar/techhider/BlockIds.java | 33 ---- .../src/de/steamwar/techhider/ChunkHider.java | 34 ---- .../de/steamwar/techhider/ProtocolUtils.java | 164 ------------------ .../steamwar/techhider/ProtocolWrapper.java | 41 ----- 18 files changed, 1272 deletions(-) delete mode 100644 FightSystem_14/src/de/steamwar/techhider/BlockIds14.java delete mode 100644 FightSystem_14/src/de/steamwar/techhider/ChunkHider14.java delete mode 100644 FightSystem_14/src/de/steamwar/techhider/ProtocolWrapper14.java delete mode 100644 FightSystem_15/src/de/steamwar/techhider/BlockIds15.java delete mode 100644 FightSystem_18/src/de/steamwar/techhider/BlockIds18.java delete mode 100644 FightSystem_18/src/de/steamwar/techhider/ChunkHider18.java delete mode 100644 FightSystem_18/src/de/steamwar/techhider/ProtocolWrapper18.java delete mode 100644 FightSystem_19/src/de/steamwar/techhider/BlockIds19.java delete mode 100644 FightSystem_19/src/de/steamwar/techhider/ChunkHider19.java delete mode 100644 FightSystem_19/src/de/steamwar/techhider/ProtocolWrapper19.java delete mode 100644 FightSystem_8/src/de/steamwar/techhider/BlockIds8.java delete mode 100644 FightSystem_8/src/de/steamwar/techhider/ChunkHider8.java delete mode 100644 FightSystem_8/src/de/steamwar/techhider/ProtocolWrapper8.java delete mode 100644 FightSystem_9/src/de/steamwar/techhider/ChunkHider9.java delete mode 100644 FightSystem_Core/src/de/steamwar/techhider/BlockIds.java delete mode 100644 FightSystem_Core/src/de/steamwar/techhider/ChunkHider.java delete mode 100644 FightSystem_Core/src/de/steamwar/techhider/ProtocolUtils.java delete mode 100644 FightSystem_Core/src/de/steamwar/techhider/ProtocolWrapper.java diff --git a/FightSystem_14/src/de/steamwar/techhider/BlockIds14.java b/FightSystem_14/src/de/steamwar/techhider/BlockIds14.java deleted file mode 100644 index 1a946ef..0000000 --- a/FightSystem_14/src/de/steamwar/techhider/BlockIds14.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.techhider; - -import net.minecraft.server.v1_14_R1.*; -import org.bukkit.Material; - -import java.util.HashSet; -import java.util.Set; - -public class BlockIds14 implements BlockIds { - @Override - public int materialToId(Material material) { - return Block.getCombinedId(IRegistry.BLOCK.get(new MinecraftKey(material.name().toLowerCase())).getBlockData()); - } - - @Override - public Set materialToAllIds(Material material) { - Set ids = new HashSet<>(); - for(IBlockData data : IRegistry.BLOCK.get(new MinecraftKey(material.name().toLowerCase())).getStates().a()) { - ids.add(Block.getCombinedId(data)); - } - - if(material == Material.WATER){ - Fluid water = FluidTypes.WATER.a(false); - for(IBlockData data : Block.REGISTRY_ID){ - if(data.p() == water){ - ids.add(Block.getCombinedId(data)); - } - } - } - - return ids; - } -} diff --git a/FightSystem_14/src/de/steamwar/techhider/ChunkHider14.java b/FightSystem_14/src/de/steamwar/techhider/ChunkHider14.java deleted file mode 100644 index eae64df..0000000 --- a/FightSystem_14/src/de/steamwar/techhider/ChunkHider14.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.techhider; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; - -import java.nio.ByteBuffer; -import java.nio.LongBuffer; -import java.util.Set; - -public class ChunkHider14 extends ChunkHider9 { - - @Override - protected byte[] dataHider(int obfuscationTarget, Set obfuscate, byte[] data, Integer primaryBitMask) { - ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100); - int i = 0; - - while(primaryBitMask != 0){ - while((primaryBitMask & 1) == 0){ - primaryBitMask >>= 1; - } - - buffer.writeBytes(data, i, 2); // Block count - i += 2; - byte bitsPerBlock = data[i++]; - buffer.writeByte(bitsPerBlock); - - if(bitsPerBlock < 9){ - int paletteLength = ProtocolUtils.readVarInt(data, i); - int paletteLengthLength = ProtocolUtils.readVarIntLength(data, i); - buffer.writeBytes(data, i, paletteLengthLength); - i += paletteLengthLength; - for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){ - int blockId = ProtocolUtils.readVarInt(data, i); - int actPaletteLength = ProtocolUtils.readVarIntLength(data, i); - - if(obfuscate.contains(blockId)){ - buffer.writeBytes(ProtocolUtils.writeVarInt(obfuscationTarget)); - }else{ - buffer.writeBytes(data, i, actPaletteLength); - } - i += actPaletteLength; - } - - //We modify only the chunk palette for performance reasons - int dataArrayLength = ProtocolUtils.readVarInt(data, i); - int dataArrayLengthLength = ProtocolUtils.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 = ProtocolUtils.readVarInt(data, i); - int dataArrayLengthLength = ProtocolUtils.readVarIntLength(data, i); - buffer.writeBytes(data, i, dataArrayLengthLength); - i += dataArrayLengthLength; - - ByteBuffer source = ByteBuffer.wrap(data, i, dataArrayLength * 8); - VariableValueArray values = new VariableValueArray(bitsPerBlock, dataArrayLength, source.asLongBuffer()); - - for(int pos = 0; pos < 4096; pos++){ - if(obfuscate.contains(values.get(pos))){ - values.set(pos, obfuscationTarget); - } - } - - for(long l : values.backing) - buffer.writeLong(l); - - i += dataArrayLength * 8; - } - - primaryBitMask >>= 1; - } - buffer.writeBytes(data, i, data.length - i); // MC appends a 0 byte at the end if there is a full chunk, idk why - - data = new byte[buffer.readableBytes()]; - buffer.readBytes(data); - return data; - } - - private static final class VariableValueArray { - private final long[] backing; - private final int bitsPerValue; - private final long valueMask; - - public VariableValueArray(int bitsPerEntry, int dataArrayLength, LongBuffer buffer) { - this.bitsPerValue = bitsPerEntry; - this.backing = new long[dataArrayLength]; - buffer.get(backing); - this.valueMask = (1L << this.bitsPerValue) - 1; - } - - public int get(int index) { - index *= bitsPerValue; - int i0 = index >> 6; - int i1 = index & 0x3f; - - long value = backing[i0] >>> i1; - - // The value is divided over two long values - if (i1 + bitsPerValue > 64) { - value |= backing[++i0] << 64 - i1; - } - - return (int) (value & valueMask); - } - - public void set(int index, int value) { - index *= bitsPerValue; - int i0 = index >> 6; - int i1 = index & 0x3f; - - backing[i0] = this.backing[i0] & ~(this.valueMask << i1) | (value & valueMask) << i1; - int i2 = i1 + bitsPerValue; - // The value is divided over two long values - if (i2 > 64) { - i0++; - backing[i0] = backing[i0] & -(1L << i2 - 64) | value >> 64 - i1; - } - } - } -} diff --git a/FightSystem_14/src/de/steamwar/techhider/ProtocolWrapper14.java b/FightSystem_14/src/de/steamwar/techhider/ProtocolWrapper14.java deleted file mode 100644 index bb52f52..0000000 --- a/FightSystem_14/src/de/steamwar/techhider/ProtocolWrapper14.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.techhider; - -import com.comphenix.tinyprotocol.Reflection; -import org.bukkit.Material; -import org.bukkit.entity.Player; - -import java.util.Set; -import java.util.function.BiFunction; -import java.util.function.UnaryOperator; - -public class ProtocolWrapper14 extends ProtocolWrapper8 { - - @Override - public BiFunction blockBreakHiderGenerator(Class blockBreakPacket, Object obfuscationTarget, Set obfuscate, TechHider.BypassEvaluator bypass) { - UnaryOperator blockBreakCloner = ProtocolUtils.shallowCloneGenerator(blockBreakPacket); - Reflection.FieldAccessor blockBreakPosition = Reflection.getField(blockBreakPacket, TechHider.blockPosition, 0); - Reflection.FieldAccessor blockBreakBlockData = Reflection.getField(blockBreakPacket, TechHider.iBlockData, 0); - - return (p, packet) -> { - Object pos = blockBreakPosition.get(packet); - if(bypass.bypass(p, ProtocolUtils.posToChunk(TechHider.blockPositionX.get(pos)), ProtocolUtils.posToChunk(TechHider.blockPositionZ.get(pos)))) - return packet; - - if(ProtocolWrapper.impl.iBlockDataHidden(obfuscate, blockBreakBlockData.get(packet))){ - packet = blockBreakCloner.apply(packet); - blockBreakBlockData.set(packet, obfuscationTarget); - } - return packet; - }; - } -} diff --git a/FightSystem_15/src/de/steamwar/techhider/BlockIds15.java b/FightSystem_15/src/de/steamwar/techhider/BlockIds15.java deleted file mode 100644 index 15e7c4d..0000000 --- a/FightSystem_15/src/de/steamwar/techhider/BlockIds15.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.techhider; - -import net.minecraft.server.v1_15_R1.*; -import org.bukkit.Material; - -import java.util.HashSet; -import java.util.Set; - -public class BlockIds15 implements BlockIds { - @Override - public int materialToId(Material material) { - return Block.getCombinedId(IRegistry.BLOCK.get(new MinecraftKey(material.name().toLowerCase())).getBlockData()); - } - - @Override - public Set materialToAllIds(Material material) { - Set ids = new HashSet<>(); - for(IBlockData data : IRegistry.BLOCK.get(new MinecraftKey(material.name().toLowerCase())).getStates().a()) { - ids.add(Block.getCombinedId(data)); - } - - if(material == Material.WATER){ - Fluid water = FluidTypes.WATER.a(false); - for(IBlockData data : Block.REGISTRY_ID){ - if(data.getFluid() == water){ - ids.add(Block.getCombinedId(data)); - } - } - } - - return ids; - } -} diff --git a/FightSystem_18/src/de/steamwar/techhider/BlockIds18.java b/FightSystem_18/src/de/steamwar/techhider/BlockIds18.java deleted file mode 100644 index 13cf029..0000000 --- a/FightSystem_18/src/de/steamwar/techhider/BlockIds18.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.techhider; - -import net.minecraft.core.IRegistry; -import net.minecraft.resources.MinecraftKey; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.level.material.Fluid; -import net.minecraft.world.level.material.FluidTypes; -import org.bukkit.Material; - -import java.util.HashSet; -import java.util.Set; - -public class BlockIds18 implements BlockIds { - @Override - public int materialToId(Material material) { - return Block.i(IRegistry.U.a(new MinecraftKey(material.name().toLowerCase())).n()); - } - - @Override - public Set materialToAllIds(Material material) { - Set ids = new HashSet<>(); - for(IBlockData data : IRegistry.U.a(new MinecraftKey(material.name().toLowerCase())).m().a()){ - ids.add(Block.i(data)); - } - - if(material == Material.WATER){ - Fluid water = FluidTypes.c.h(); - for(IBlockData data : Block.o) { - if(data.o() == water) { - ids.add(Block.i(data)); - } - } - } - - return ids; - } -} diff --git a/FightSystem_18/src/de/steamwar/techhider/ChunkHider18.java b/FightSystem_18/src/de/steamwar/techhider/ChunkHider18.java deleted file mode 100644 index 53dc78f..0000000 --- a/FightSystem_18/src/de/steamwar/techhider/ChunkHider18.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.techhider; - -import com.comphenix.tinyprotocol.Reflection; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; -import net.minecraft.core.IRegistry; -import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData; -import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; -import net.minecraft.util.SimpleBitStorage; -import net.minecraft.world.level.block.entity.TileEntityTypes; -import org.bukkit.World; -import org.bukkit.entity.Player; - -import java.nio.ByteBuffer; -import java.util.List; -import java.util.Set; -import java.util.function.BiFunction; -import java.util.function.IntFunction; -import java.util.function.UnaryOperator; -import java.util.stream.Collectors; - -public class ChunkHider18 implements ChunkHider { - @Override - public Class mapChunkPacket() { - return ClientboundLevelChunkWithLightPacket.class; - } - - private static final UnaryOperator chunkPacketCloner = ProtocolUtils.shallowCloneGenerator(ClientboundLevelChunkWithLightPacket.class); - private static final UnaryOperator chunkDataCloner = ProtocolUtils.shallowCloneGenerator(ClientboundLevelChunkPacketData.class); - - private static final Reflection.FieldAccessor chunkX = Reflection.getField(ClientboundLevelChunkWithLightPacket.class, int.class, 0); - private static final Reflection.FieldAccessor chunkZ = Reflection.getField(ClientboundLevelChunkWithLightPacket.class, int.class, 1); - private static final Reflection.FieldAccessor chunkData = Reflection.getField(ClientboundLevelChunkWithLightPacket.class, ClientboundLevelChunkPacketData.class, 0); - - private static final Reflection.FieldAccessor dataField = Reflection.getField(ClientboundLevelChunkPacketData.class, byte[].class, 0); - private static final Reflection.FieldAccessor tileEntities = Reflection.getField(ClientboundLevelChunkPacketData.class, List.class, 0); - public static final Class tileEntity = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$a"); - protected static final Reflection.FieldAccessor entityType = Reflection.getField(tileEntity, TileEntityTypes.class, 0); - - @Override - public BiFunction chunkHiderGenerator(TechHider.BypassEvaluator bypass, int obfuscationTarget, Set obfuscate, Set hiddenBlockEntities) { - return (p, packet) -> { - if(bypass.bypass(p, chunkX.get(packet), chunkZ.get(packet))) - return packet; - - packet = chunkPacketCloner.apply(packet); - Object data = chunkDataCloner.apply(chunkData.get(packet)); - - tileEntities.set(data, ((List)tileEntities.get(data)).stream().filter(te -> tileEntityVisible(hiddenBlockEntities, te)).collect(Collectors.toList())); - - World world = p.getWorld(); - int sections = (world.getMaxHeight() - world.getMinHeight()) / 16; - dataField.set(data, dataHider(obfuscationTarget, obfuscate, dataField.get(data), sections)); - - chunkData.set(packet, data); - return packet; - }; - } - - protected boolean tileEntityVisible(Set hiddenBlockEntities, Object tile) { - return !hiddenBlockEntities.contains(IRegistry.aa.b(entityType.get(tile)).a()); - } - - private byte[] dataHider(int obfuscationTarget, Set obfuscate, byte[] data, int sections) { - ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100); - int i = 0; - - while(sections-- > 0) { - buffer.writeBytes(data, i, 2); // Block count - i += 2; - - i = containerWalker(data, buffer, i, 15, blockId -> obfuscate.contains(blockId) ? obfuscationTarget : blockId, (curI, dataArrayLength, bitsPerBlock) -> { - if(bitsPerBlock < 15) { - buffer.writeBytes(data, curI, dataArrayLength * 8); - } else { - ByteBuffer source = ByteBuffer.wrap(data, curI, dataArrayLength * 8); - long[] array = new long[dataArrayLength]; - source.asLongBuffer().get(array); - SimpleBitStorage values = new SimpleBitStorage(bitsPerBlock, 4096, array); - - for (int pos = 0; pos < 4096; pos++) { - if (obfuscate.contains(values.a(pos))) { - values.b(pos, obfuscationTarget); - } - } - - for (long l : values.a()) - buffer.writeLong(l); - } - }); - i = containerWalker(data, buffer, i, 6, value -> value, (curI, dataArrayLength, bitsPerBlock) -> buffer.writeBytes(data, curI, dataArrayLength * 8)); - } - buffer.writeBytes(data, i, data.length - i); // MC appends a 0 byte at the end if there is a full chunk, idk why - - byte[] outdata = new byte[buffer.readableBytes()]; - buffer.readBytes(outdata); - return outdata; - } - - private int containerWalker(byte[] data, ByteBuf buffer, int i, int globalPalette, IntFunction palette, TriConsumer dataArray) { - byte bitsPerBlock = data[i++]; - buffer.writeByte(bitsPerBlock); - - if(bitsPerBlock == 0) { - int paletteValue = ProtocolUtils.readVarInt(data, i); - i += ProtocolUtils.readVarIntLength(data, i); - buffer.writeBytes(ProtocolUtils.writeVarInt(palette.apply(paletteValue))); - }else if(bitsPerBlock < globalPalette) { - int paletteLength = ProtocolUtils.readVarInt(data, i); - int paletteLengthLength = ProtocolUtils.readVarIntLength(data, i); - buffer.writeBytes(data, i, paletteLengthLength); - i += paletteLengthLength; - - for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++) { - int paletteValue = ProtocolUtils.readVarInt(data, i); - i += ProtocolUtils.readVarIntLength(data, i); - buffer.writeBytes(ProtocolUtils.writeVarInt(palette.apply(paletteValue))); - } - } - - int dataArrayLength = ProtocolUtils.readVarInt(data, i); - int dataArrayLengthLength = ProtocolUtils.readVarIntLength(data, i); - buffer.writeBytes(data, i, dataArrayLengthLength); - i += dataArrayLengthLength; - - dataArray.accept(i, dataArrayLength, bitsPerBlock); - i += dataArrayLength * 8; - - return i; - } - - private interface TriConsumer { - void accept(X x, Y y, Z z); - } -} diff --git a/FightSystem_18/src/de/steamwar/techhider/ProtocolWrapper18.java b/FightSystem_18/src/de/steamwar/techhider/ProtocolWrapper18.java deleted file mode 100644 index 7edbd8d..0000000 --- a/FightSystem_18/src/de/steamwar/techhider/ProtocolWrapper18.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.techhider; - -import com.comphenix.tinyprotocol.Reflection; -import net.minecraft.core.IRegistry; -import net.minecraft.core.SectionPosition; -import net.minecraft.network.protocol.game.PacketPlayOutBlockBreak; -import net.minecraft.world.level.block.entity.TileEntityTypes; -import net.minecraft.world.level.block.state.IBlockData; -import org.bukkit.Material; -import org.bukkit.entity.Player; - -import java.util.Set; -import java.util.function.BiFunction; -import java.util.function.UnaryOperator; - -public class ProtocolWrapper18 implements ProtocolWrapper { - - private static final Reflection.FieldAccessor multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, SectionPosition.class, 0); - private static final Reflection.FieldAccessor multiBlockChangeBlocks = Reflection.getField(TechHider.multiBlockChangePacket, IBlockData[].class, 0); - private static final BiFunction, Object> iBlockDataArrayCloner = ProtocolUtils.arrayCloneGenerator(TechHider.iBlockData); - @Override - public BiFunction multiBlockChangeGenerator(Object obfuscationTarget, Set obfuscate, TechHider.BypassEvaluator bypass) { - return (p, packet) -> { - Object chunkCoords = multiBlockChangeChunk.get(packet); - if(bypass.bypass(p, TechHider.blockPositionX.get(chunkCoords), TechHider.blockPositionZ.get(chunkCoords))) - return packet; - - packet = TechHider.multiBlockChangeCloner.apply(packet); - multiBlockChangeBlocks.set(packet, iBlockDataArrayCloner.apply(multiBlockChangeBlocks.get(packet), block -> ProtocolWrapper.impl.iBlockDataHidden(obfuscate, block) ? obfuscationTarget : block)); - return packet; - }; - } - - private static final Reflection.FieldAccessor tileEntityType = Reflection.getField(TechHider.tileEntityDataPacket, TileEntityTypes.class, 0); - @Override - public boolean unfilteredTileEntityDataAction(Object packet) { - return tileEntityType.get(packet) != TileEntityTypes.h; - } - - @Override - public BiFunction blockBreakHiderGenerator(Class blockBreakPacket, Object obfuscationTarget, Set obfuscate, TechHider.BypassEvaluator bypass) { - return (p, packet) -> { - PacketPlayOutBlockBreak breakPacket = (PacketPlayOutBlockBreak) packet; - if(bypass.bypass(p, ProtocolUtils.posToChunk(TechHider.blockPositionX.get(breakPacket.b())), ProtocolUtils.posToChunk(TechHider.blockPositionZ.get(breakPacket.b())))) - return packet; - - if(!ProtocolWrapper.impl.iBlockDataHidden(obfuscate, breakPacket.c())) - return packet; - - return new PacketPlayOutBlockBreak(breakPacket.b(), (IBlockData) obfuscationTarget, breakPacket.d(), breakPacket.a()); - }; - } - - @Override - public boolean iBlockDataHidden(Set obfuscate, Object iBlockData) { - return obfuscate.contains(Material.getMaterial(IRegistry.U.b(((IBlockData) iBlockData).b()).a().toUpperCase())); - } -} diff --git a/FightSystem_19/src/de/steamwar/techhider/BlockIds19.java b/FightSystem_19/src/de/steamwar/techhider/BlockIds19.java deleted file mode 100644 index e1e0b54..0000000 --- a/FightSystem_19/src/de/steamwar/techhider/BlockIds19.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.techhider; - -import net.minecraft.core.IRegistry; -import net.minecraft.resources.MinecraftKey; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.level.material.Fluid; -import net.minecraft.world.level.material.FluidTypes; -import org.bukkit.Material; - -import java.util.HashSet; -import java.util.Set; - -public class BlockIds19 implements BlockIds { - @Override - public int materialToId(Material material) { - return Block.i(IRegistry.V.a(new MinecraftKey(material.name().toLowerCase())).m()); - } - - @Override - public Set materialToAllIds(Material material) { - Set ids = new HashSet<>(); - for(IBlockData data : IRegistry.V.a(new MinecraftKey(material.name().toLowerCase())).k().a()){ - ids.add(Block.i(data)); - } - - if(material == Material.WATER){ - Fluid water = FluidTypes.c.h(); - for(IBlockData data : Block.o) { - if(data.p() == water) { - ids.add(Block.i(data)); - } - } - } - - return ids; - } -} diff --git a/FightSystem_19/src/de/steamwar/techhider/ChunkHider19.java b/FightSystem_19/src/de/steamwar/techhider/ChunkHider19.java deleted file mode 100644 index 0ebba1c..0000000 --- a/FightSystem_19/src/de/steamwar/techhider/ChunkHider19.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.techhider; - -import net.minecraft.core.IRegistry; - -import java.util.Set; - -public class ChunkHider19 extends ChunkHider18 { - @Override - protected boolean tileEntityVisible(Set hiddenBlockEntities, Object tile) { - return !hiddenBlockEntities.contains(IRegistry.ab.b(entityType.get(tile)).a()); - } -} diff --git a/FightSystem_19/src/de/steamwar/techhider/ProtocolWrapper19.java b/FightSystem_19/src/de/steamwar/techhider/ProtocolWrapper19.java deleted file mode 100644 index 240f854..0000000 --- a/FightSystem_19/src/de/steamwar/techhider/ProtocolWrapper19.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.techhider; - -import com.comphenix.tinyprotocol.Reflection; -import net.minecraft.core.IRegistry; -import net.minecraft.core.SectionPosition; -import net.minecraft.world.level.block.entity.TileEntityTypes; -import net.minecraft.world.level.block.state.IBlockData; -import org.bukkit.Material; -import org.bukkit.entity.Player; - -import java.util.Set; -import java.util.function.BiFunction; -import java.util.function.UnaryOperator; - -public class ProtocolWrapper19 implements ProtocolWrapper { - - private static final Reflection.FieldAccessor multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, SectionPosition.class, 0); - private static final Reflection.FieldAccessor multiBlockChangeBlocks = Reflection.getField(TechHider.multiBlockChangePacket, IBlockData[].class, 0); - private static final BiFunction, Object> iBlockDataArrayCloner = ProtocolUtils.arrayCloneGenerator(TechHider.iBlockData); - @Override - public BiFunction multiBlockChangeGenerator(Object obfuscationTarget, Set obfuscate, TechHider.BypassEvaluator bypass) { - return (p, packet) -> { - Object chunkCoords = multiBlockChangeChunk.get(packet); - if(bypass.bypass(p, TechHider.blockPositionX.get(chunkCoords), TechHider.blockPositionZ.get(chunkCoords))) - return packet; - - packet = TechHider.multiBlockChangeCloner.apply(packet); - multiBlockChangeBlocks.set(packet, iBlockDataArrayCloner.apply(multiBlockChangeBlocks.get(packet), block -> ProtocolWrapper.impl.iBlockDataHidden(obfuscate, block) ? obfuscationTarget : block)); - return packet; - }; - } - - private static final Reflection.FieldAccessor tileEntityType = Reflection.getField(TechHider.tileEntityDataPacket, TileEntityTypes.class, 0); - @Override - public boolean unfilteredTileEntityDataAction(Object packet) { - return tileEntityType.get(packet) != TileEntityTypes.h; - } - - @Override - public BiFunction blockBreakHiderGenerator(Class blockBreakPacket, Object obfuscationTarget, Set obfuscate, TechHider.BypassEvaluator bypass) { - return null; - } - - @Override - public boolean iBlockDataHidden(Set obfuscate, Object iBlockData) { - return obfuscate.contains(Material.getMaterial(IRegistry.V.b(((IBlockData) iBlockData).b()).a().toUpperCase())); - } -} diff --git a/FightSystem_8/src/de/steamwar/techhider/BlockIds8.java b/FightSystem_8/src/de/steamwar/techhider/BlockIds8.java deleted file mode 100644 index 538e8db..0000000 --- a/FightSystem_8/src/de/steamwar/techhider/BlockIds8.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.techhider; - -import org.bukkit.Material; - -import java.util.Collections; -import java.util.Set; - -public class BlockIds8 implements BlockIds { - @Override - @SuppressWarnings("deprecation") - public int materialToId(Material material) { - return material.getId() << 4; - } - - @Override - public Set materialToAllIds(Material material) { - return Collections.singleton(materialToId(material)); - } -} diff --git a/FightSystem_8/src/de/steamwar/techhider/ChunkHider8.java b/FightSystem_8/src/de/steamwar/techhider/ChunkHider8.java deleted file mode 100644 index 3cc0d36..0000000 --- a/FightSystem_8/src/de/steamwar/techhider/ChunkHider8.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.techhider; - -import com.comphenix.tinyprotocol.Reflection; -import org.bukkit.entity.Player; - -import java.util.Set; -import java.util.function.BiFunction; - -public class ChunkHider8 implements ChunkHider { - - protected static final Class mapChunkPacket = Reflection.getClass("{nms}.PacketPlayOutMapChunk"); - @Override - public Class mapChunkPacket() { - return mapChunkPacket; - } - - @Override - public BiFunction chunkHiderGenerator(TechHider.BypassEvaluator bypass, int obfuscationTarget, Set obfuscate, Set hiddenBlockEntities) { - return null; - } -} diff --git a/FightSystem_8/src/de/steamwar/techhider/ProtocolWrapper8.java b/FightSystem_8/src/de/steamwar/techhider/ProtocolWrapper8.java deleted file mode 100644 index abc9e61..0000000 --- a/FightSystem_8/src/de/steamwar/techhider/ProtocolWrapper8.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.techhider; - -import com.comphenix.tinyprotocol.Reflection; -import org.bukkit.Material; -import org.bukkit.entity.Player; - -import java.util.Set; -import java.util.function.BiFunction; -import java.util.function.UnaryOperator; - -public class ProtocolWrapper8 implements ProtocolWrapper { - private static final Class chunkCoordinateIntPair = Reflection.getClass("{nms}.ChunkCoordIntPair"); - private static final Reflection.FieldAccessor multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, chunkCoordinateIntPair, 0); - private static final Reflection.FieldAccessor chunkCoordinateX = Reflection.getField(chunkCoordinateIntPair, int.class, 0); - private static final Reflection.FieldAccessor chunkCoordinateZ = Reflection.getField(chunkCoordinateIntPair, int.class, 1); - private static final Class multiBlockChangeInfo = Reflection.getClass("{nms}.PacketPlayOutMultiBlockChange$MultiBlockChangeInfo"); - private static final Reflection.ConstructorInvoker multiBlockChangeInfoConstructor = Reflection.getConstructor(multiBlockChangeInfo, TechHider.multiBlockChangePacket, short.class, TechHider.iBlockData); - private static final BiFunction, Object> multiBlockChangeInfoArrayCloner = ProtocolUtils.arrayCloneGenerator(multiBlockChangeInfo); - private static final Reflection.FieldAccessor multiBlockChangeInfoBlock = Reflection.getField(multiBlockChangeInfo, TechHider.iBlockData, 0); - private static final Reflection.FieldAccessor multiBlockChangeInfoPos = Reflection.getField(multiBlockChangeInfo, short.class, 0); - private static final Class multiBlockChangeInfoArray = Reflection.getClass("[L{nms}.PacketPlayOutMultiBlockChange$MultiBlockChangeInfo;"); - private static final Reflection.FieldAccessor multiBlockChangeInfos = Reflection.getField(TechHider.multiBlockChangePacket, multiBlockChangeInfoArray, 0); - @Override - public BiFunction multiBlockChangeGenerator(Object obfuscationTarget, Set obfuscate, TechHider.BypassEvaluator bypass) { - return (p, packet) -> { - Object chunkCoords = multiBlockChangeChunk.get(packet); - if(bypass.bypass(p, chunkCoordinateX.get(chunkCoords), chunkCoordinateZ.get(chunkCoords))) - return packet; - - Object modpacket = TechHider.multiBlockChangeCloner.apply(packet); - multiBlockChangeInfos.set(modpacket, multiBlockChangeInfoArrayCloner.apply(multiBlockChangeInfos.get(modpacket), mbci -> { - if(ProtocolWrapper.impl.iBlockDataHidden(obfuscate, multiBlockChangeInfoBlock.get(mbci))) - return multiBlockChangeInfoConstructor.invoke(modpacket, multiBlockChangeInfoPos.get(mbci), obfuscationTarget); - return mbci; - })); - return modpacket; - }; - } - - private static final Reflection.FieldAccessor tileEntityDataAction = Reflection.getField(TechHider.tileEntityDataPacket, int.class, 0); - @Override - public boolean unfilteredTileEntityDataAction(Object packet) { - return tileEntityDataAction.get(packet) != 9; - } - - @Override - public BiFunction blockBreakHiderGenerator(Class blockBreakPacket, Object obfuscationTarget, Set obfuscate, TechHider.BypassEvaluator bypass) { - return null; - } - - private static final Reflection.MethodInvoker getBlockByBlockData = Reflection.getTypedMethod(TechHider.iBlockData, null, TechHider.block); - private static final Reflection.MethodInvoker getMaterialByBlock = Reflection.getTypedMethod(TechHider.craftMagicNumbers, "getMaterial", Material.class, TechHider.block); - @Override - public boolean iBlockDataHidden(Set obfuscate, Object iBlockData) { - return obfuscate.contains((Material) getMaterialByBlock.invoke(null, getBlockByBlockData.invoke(iBlockData))); - } -} diff --git a/FightSystem_9/src/de/steamwar/techhider/ChunkHider9.java b/FightSystem_9/src/de/steamwar/techhider/ChunkHider9.java deleted file mode 100644 index 0272dd6..0000000 --- a/FightSystem_9/src/de/steamwar/techhider/ChunkHider9.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.techhider; - -import com.comphenix.tinyprotocol.Reflection; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import java.util.List; -import java.util.Set; -import java.util.function.BiFunction; -import java.util.function.UnaryOperator; -import java.util.logging.Level; -import java.util.stream.Collectors; - -public class ChunkHider9 extends ChunkHider8 { - - private static final UnaryOperator mapChunkCloner = ProtocolUtils.shallowCloneGenerator(mapChunkPacket); - - private static final Reflection.FieldAccessor mapChunkX = Reflection.getField(mapChunkPacket, int.class, 0); - private static final Reflection.FieldAccessor mapChunkZ = Reflection.getField(mapChunkPacket, int.class, 1); - private static final Reflection.FieldAccessor mapChunkBitMask = Reflection.getField(mapChunkPacket, int.class, 2); - private static final Reflection.FieldAccessor mapChunkBlockEntities = Reflection.getField(mapChunkPacket, List.class, 0); - private static final Reflection.FieldAccessor mapChunkData = Reflection.getField(mapChunkPacket, byte[].class, 0); - - private static final Class nbtTagCompound = Reflection.getClass("{nms.nbt}.NBTTagCompound"); - private static final Reflection.MethodInvoker nbtTagGetString = Reflection.getTypedMethod(nbtTagCompound, null, String.class, String.class); - - @Override - public BiFunction chunkHiderGenerator(TechHider.BypassEvaluator bypass, int obfuscationTarget, Set obfuscate, Set hiddenBlockEntities) { - return (p, packet) -> { - if(bypass.bypass(p, mapChunkX.get(packet), mapChunkZ.get(packet))) - return packet; - - packet = mapChunkCloner.apply(packet); - mapChunkBlockEntities.set(packet, ((List)mapChunkBlockEntities.get(packet)).stream().filter( - nbttag -> !hiddenBlockEntities.contains((String) nbtTagGetString.invoke(nbttag, "id")) - ).collect(Collectors.toList())); - - byte[] data = dataHider(obfuscationTarget, obfuscate, mapChunkData.get(packet), mapChunkBitMask.get(packet)); - mapChunkData.set(packet, data); - - return packet; - }; - } - - protected byte[] dataHider(int obfuscationTarget, Set obfuscate, byte[] data, Integer primaryBitMask) { - ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100); - int i = 0; - - while(i < data.length){ - byte bitsPerBlock = data[i++]; - buffer.writeByte(bitsPerBlock); - - if(bitsPerBlock != 13){ - int paletteLength = ProtocolUtils.readVarInt(data, i); - int paletteLengthLength = ProtocolUtils.readVarIntLength(data, i); - buffer.writeBytes(data, i, paletteLengthLength); - i += paletteLengthLength; - - for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){ - int entry = ProtocolUtils.readVarInt(data, i); - i += ProtocolUtils.readVarIntLength(data, i); - - if(obfuscate.contains(entry)){ - entry = obfuscationTarget; - } - buffer.writeBytes(ProtocolUtils.writeVarInt(entry)); - } - }else{ - buffer.writeByte(data[++i]); //Empty palette - Bukkit.getLogger().log(Level.SEVERE, "Full chunk occured"); - } - - int dataArrayLength = ProtocolUtils.readVarInt(data, i); - int dataArrayLengthLength = ProtocolUtils.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 - } - - data = new byte[buffer.readableBytes()]; - buffer.readBytes(data); - return data; - } -} diff --git a/FightSystem_Core/src/de/steamwar/techhider/BlockIds.java b/FightSystem_Core/src/de/steamwar/techhider/BlockIds.java deleted file mode 100644 index 1ab7353..0000000 --- a/FightSystem_Core/src/de/steamwar/techhider/BlockIds.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.techhider; - -import de.steamwar.core.VersionDependent; -import de.steamwar.fightsystem.FightSystem; -import org.bukkit.Material; - -import java.util.Set; - -public interface BlockIds { - BlockIds impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); - - int materialToId(Material material); - Set materialToAllIds(Material material); -} diff --git a/FightSystem_Core/src/de/steamwar/techhider/ChunkHider.java b/FightSystem_Core/src/de/steamwar/techhider/ChunkHider.java deleted file mode 100644 index 0711f37..0000000 --- a/FightSystem_Core/src/de/steamwar/techhider/ChunkHider.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2022 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.techhider; - -import de.steamwar.core.VersionDependent; -import de.steamwar.fightsystem.FightSystem; -import org.bukkit.entity.Player; - -import java.util.Set; -import java.util.function.BiFunction; - -public interface ChunkHider { - ChunkHider impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); - - Class mapChunkPacket(); - BiFunction chunkHiderGenerator(TechHider.BypassEvaluator bypass, int obfuscationTarget, Set obfuscate, Set hiddenBlockEntities); -} diff --git a/FightSystem_Core/src/de/steamwar/techhider/ProtocolUtils.java b/FightSystem_Core/src/de/steamwar/techhider/ProtocolUtils.java deleted file mode 100644 index 1fc9e31..0000000 --- a/FightSystem_Core/src/de/steamwar/techhider/ProtocolUtils.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2022 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.techhider; - -import com.comphenix.tinyprotocol.Reflection; -import com.comphenix.tinyprotocol.TinyProtocol; -import com.google.common.primitives.Bytes; -import org.bukkit.Bukkit; - -import java.lang.reflect.Array; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.List; -import java.util.function.BiConsumer; -import java.util.function.BiFunction; -import java.util.function.UnaryOperator; - -public class ProtocolUtils { - private ProtocolUtils() {} - - public static void broadcastPacket(Object packet) { - Bukkit.getOnlinePlayers().stream().map(TinyProtocol.instance::getChannel).filter(TinyProtocol.instance::hasInjected).forEach(channel -> TinyProtocol.instance.sendPacket(channel, packet)); - } - - public static BiFunction, Object> arrayCloneGenerator(Class elementClass) { - return (array, worker) -> { - int length = Array.getLength(array); - Object result = Array.newInstance(elementClass, length); - - for(int i = 0; i < length; i++) - Array.set(result, i, worker.apply(Array.get(array, i))); - - return result; - }; - } - - public static UnaryOperator shallowCloneGenerator(Class clazz) { - BiConsumer filler = shallowFill(clazz); - - return source -> { - Object clone = Reflection.newInstance(clazz); - filler.accept(source, clone); - return clone; - }; - } - - private static BiConsumer shallowFill(Class clazz) { - if(clazz == null) - return (source, clone) -> {}; - - BiConsumer superFiller = shallowFill(clazz.getSuperclass()); - - Field[] fds = clazz.getDeclaredFields(); - List fields = new ArrayList<>(); - for(Field field : fds) { - if (Modifier.isStatic(field.getModifiers())) - continue; - - field.setAccessible(true); - fields.add(field); - } - - return (source, clone) -> { - superFiller.accept(source, clone); - try { - for(Field field : fields) { - field.set(clone, field.get(source)); - } - } catch (IllegalAccessException e) { - throw new IllegalStateException("Could not set field", e); - } - - }; - } - - public static int posToChunk(int c){ - int chunk = c / 16; - if(c<0) - chunk--; - return chunk; - } - - public static int readVarInt(byte[] array, int startPos) { - int numRead = 0; - int result = 0; - byte read; - do { - read = array[startPos + numRead]; - int value = (read & 0b01111111); - result |= (value << (7 * numRead)); - - numRead++; - if (numRead > 5) { - break; - } - } while ((read & 0b10000000) != 0); - - return result; - } - - public static int readVarIntLength(byte[] array, int startPos) { - int numRead = 0; - byte read; - do { - read = array[startPos + numRead]; - numRead++; - if (numRead > 5) { - break; - } - } while ((read & 0b10000000) != 0); - - return numRead; - } - - public static byte[] writeVarInt(int value) { - List buffer = new ArrayList<>(5); - do { - byte temp = (byte)(value & 0b01111111); - // Note: >>> means that the sign bit is shifted with the rest of the number rather than being left alone - value >>>= 7; - if (value != 0) { - temp |= 0b10000000; - } - buffer.add(temp); - } while (value != 0); - return Bytes.toArray(buffer); - } - - public static class ChunkPos{ - final int x; - final int z; - - public ChunkPos(int x, int z){ - this.x = x; - this.z = z; - } - - public final int x(){ - return x; - } - - public final int z(){ - return z; - } - } -} diff --git a/FightSystem_Core/src/de/steamwar/techhider/ProtocolWrapper.java b/FightSystem_Core/src/de/steamwar/techhider/ProtocolWrapper.java deleted file mode 100644 index 49da27d..0000000 --- a/FightSystem_Core/src/de/steamwar/techhider/ProtocolWrapper.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.techhider; - -import de.steamwar.core.VersionDependent; -import de.steamwar.fightsystem.FightSystem; -import org.bukkit.Material; -import org.bukkit.entity.Player; - -import java.util.Set; -import java.util.function.BiFunction; - -public interface ProtocolWrapper { - ProtocolWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); - - - boolean unfilteredTileEntityDataAction(Object packet); - - BiFunction blockBreakHiderGenerator(Class blockBreakPacket, Object obfuscationTarget, Set obfuscate, TechHider.BypassEvaluator bypass); - - BiFunction multiBlockChangeGenerator(Object obfuscationTarget, Set obfuscate, TechHider.BypassEvaluator bypass); - - boolean iBlockDataHidden(Set obfuscate, Object iBlockData); -} -- 2.39.2 From 332c47d4b4b4311130da70ab3325d7379b5829e5 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 22 Aug 2022 13:06:22 +0200 Subject: [PATCH 3/3] Fix duplication of TechHider.java Signed-off-by: Lixfel --- .../src/de/steamwar/techhider/TechHider.java | 128 ------------------ 1 file changed, 128 deletions(-) delete mode 100644 FightSystem_Core/src/de/steamwar/techhider/TechHider.java diff --git a/FightSystem_Core/src/de/steamwar/techhider/TechHider.java b/FightSystem_Core/src/de/steamwar/techhider/TechHider.java deleted file mode 100644 index 7f089e0..0000000 --- a/FightSystem_Core/src/de/steamwar/techhider/TechHider.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.techhider; - -import com.comphenix.tinyprotocol.Reflection; -import com.comphenix.tinyprotocol.TinyProtocol; -import de.steamwar.core.Core; -import org.bukkit.GameMode; -import org.bukkit.Material; -import org.bukkit.entity.Player; - -import java.util.*; -import java.util.function.BiFunction; -import java.util.function.Function; -import java.util.function.UnaryOperator; -import java.util.stream.Collectors; - -public class TechHider { - - public static final Class blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); - private static final Class baseBlockPosition = Reflection.getClass("{nms.core}.BaseBlockPosition"); - public static final Reflection.FieldAccessor blockPositionX = Reflection.getField(baseBlockPosition, int.class, 0); - public static final Reflection.FieldAccessor blockPositionZ = Reflection.getField(baseBlockPosition, int.class, 2); - - public static final Class iBlockData = Reflection.getClass("{nms.world.level.block.state}.IBlockData"); - public static final Class block = Reflection.getClass("{nms.world.level.block}.Block"); - private static final Reflection.MethodInvoker getBlockDataByBlock = Reflection.getTypedMethod(block, null, iBlockData); - - public static final Class craftMagicNumbers = Reflection.getClass("{obc}.util.CraftMagicNumbers"); - private static final Reflection.MethodInvoker getBlockByMaterial = Reflection.getTypedMethod(craftMagicNumbers, "getBlock", block, Material.class); - - private final Map, BiFunction> techhiders = new HashMap<>(); - private final BypassEvaluator bypass; - private final Object obfuscationTarget; - private final Set obfuscate; - - public TechHider(BypassEvaluator bypass, Material obfuscationTarget, Set obfuscate, Set hiddenBlockEntities) { - this.bypass = bypass; - this.obfuscate = obfuscate; - this.obfuscationTarget = getBlockDataByBlock.invoke(getBlockByMaterial.invoke(null, obfuscationTarget)); - - techhiders.put(blockActionPacket, this::blockActionHider); - techhiders.put(blockChangePacket, this::blockChangeHider); - techhiders.put(tileEntityDataPacket, this::tileEntityDataHider); - techhiders.put(multiBlockChangePacket,ProtocolWrapper.impl.multiBlockChangeGenerator(obfuscationTarget, obfuscate, bypass)); - techhiders.put(ChunkHider.impl.mapChunkPacket(), ChunkHider.impl.chunkHiderGenerator(bypass, BlockIds.impl.materialToId(obfuscationTarget), obfuscate.stream().flatMap(m -> BlockIds.impl.materialToAllIds(m).stream()).collect(Collectors.toSet()), hiddenBlockEntities)); - - if(Core.getVersion() > 12 && Core.getVersion() < 19) { - Class blockBreakClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutBlockBreak"); - techhiders.put(blockBreakClass, ProtocolWrapper.impl.blockBreakHiderGenerator(blockBreakClass, obfuscationTarget, obfuscate, bypass)); - } - - if(Core.getVersion() > 8){ - techhiders.put(Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem"), (p, packet) -> p.getGameMode() == GameMode.SPECTATOR ? null : packet); - } - techhiders.put(Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity"), (p, packet) -> p.getGameMode() == GameMode.SPECTATOR ? null : packet); - - } - - public void enable() { - techhiders.forEach(TinyProtocol.instance::addFilter); - } - - public void disable() { - techhiders.forEach(TinyProtocol.instance::removeFilter); - } - - public static final Class multiBlockChangePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutMultiBlockChange"); - public static final UnaryOperator multiBlockChangeCloner = ProtocolUtils.shallowCloneGenerator(TechHider.multiBlockChangePacket); - - private static final Class blockChangePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutBlockChange"); - private static final Function blockChangeCloner = ProtocolUtils.shallowCloneGenerator(blockChangePacket); - private static final Reflection.FieldAccessor blockChangePosition = Reflection.getField(blockChangePacket, blockPosition, 0); - private static final Reflection.FieldAccessor blockChangeBlockData = Reflection.getField(blockChangePacket, iBlockData, 0); - private Object blockChangeHider(Player p, Object packet) { - Object pos = blockChangePosition.get(packet); - if(bypass.bypass(p, ProtocolUtils.posToChunk(blockPositionX.get(pos)), ProtocolUtils.posToChunk(blockPositionZ.get(pos)))) - return packet; - - if(ProtocolWrapper.impl.iBlockDataHidden(obfuscate, blockChangeBlockData.get(packet))) { - packet = blockChangeCloner.apply(packet); - blockChangeBlockData.set(packet, obfuscationTarget); - } - return packet; - } - - private static final Class blockActionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutBlockAction"); - private static final Reflection.FieldAccessor blockActionPosition = Reflection.getField(blockActionPacket, blockPosition, 0); - private Object blockActionHider(Player p, Object packet) { - Object pos = blockActionPosition.get(packet); - if(bypass.bypass(p, ProtocolUtils.posToChunk(blockPositionX.get(pos)), ProtocolUtils.posToChunk(blockPositionZ.get(pos)))) - return packet; - return null; - } - - public static final Class tileEntityDataPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutTileEntityData"); - private static final Reflection.FieldAccessor tileEntityDataPosition = Reflection.getField(tileEntityDataPacket, blockPosition, 0); - private Object tileEntityDataHider(Player p, Object packet) { - Object pos = tileEntityDataPosition.get(packet); - if(bypass.bypass(p, ProtocolUtils.posToChunk(blockPositionX.get(pos)), ProtocolUtils.posToChunk(blockPositionZ.get(pos)))) - return packet; - - if(ProtocolWrapper.impl.unfilteredTileEntityDataAction(packet)) - return packet; - return null; - } - - public interface BypassEvaluator { - boolean bypass(Player p, int chunkX, int chunkZ); - } -} -- 2.39.2