From f0a9c5c3147d1ecff1ebca2d5b09add0446f5aaa Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 19 Dec 2021 16:58:52 +0100 Subject: [PATCH 1/5] Configuration Signed-off-by: Lixfel --- FightSystem_18/pom.xml | 60 +++++++++++++++++++ FightSystem_Core/pom.xml | 21 +++++-- .../steamwar/fightsystem/utils/TechHider.java | 26 ++++---- FightSystem_Main/pom.xml | 6 ++ pom.xml | 13 ++++ 5 files changed, 109 insertions(+), 17 deletions(-) create mode 100644 FightSystem_18/pom.xml diff --git a/FightSystem_18/pom.xml b/FightSystem_18/pom.xml new file mode 100644 index 0000000..d854f64 --- /dev/null +++ b/FightSystem_18/pom.xml @@ -0,0 +1,60 @@ + + + + + 4.0.0 + + + steamwar + FightSystem + 1.0 + + + + ${project.basedir}/.. + + + FightSystem_18 + 1.0 + + + + steamwar + Spigot + 1.18 + system + ${main.basedir}/lib/Spigot-1.18.jar + + + steamwar + WorldEdit + 1.0 + system + ${main.basedir}/lib/WorldEdit-1.15.jar + + + steamwar + FightSystem_Core + 1.0 + + + \ No newline at end of file diff --git a/FightSystem_Core/pom.xml b/FightSystem_Core/pom.xml index a9f81ed..f427dfc 100644 --- a/FightSystem_Core/pom.xml +++ b/FightSystem_Core/pom.xml @@ -19,11 +19,22 @@ - steamwar - Spigot - 1.15 - system - ${main.basedir}/lib/Spigot-1.15.jar + org.spigotmc + spigot-api + 1.18-R0.1-SNAPSHOT + provided + + + io.netty + netty-all + 4.1.68.Final + provided + + + com.mojang + authlib + 1.5.25 + provided steamwar diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java index 61d9085..1c27435 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java @@ -43,15 +43,15 @@ import java.util.stream.Collectors; public class TechHider extends StateDependent { - private static final Class blockPosition = Reflection.getClass("{nms}.BlockPosition"); - private static final Class baseBlockPosition = Reflection.getClass("{nms}.BaseBlockPosition"); + private static final Class blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); + private static final Class baseBlockPosition = Reflection.getClass("{nms.core}.BaseBlockPosition"); private static final Reflection.FieldAccessor blockPositionX = Reflection.getField(baseBlockPosition, int.class, 0); private static final Reflection.FieldAccessor blockPositionZ = Reflection.getField(baseBlockPosition, int.class, 2); - private static final Class iBlockData = Reflection.getClass("{nms}.IBlockData"); - private static final Class block = Reflection.getClass("{nms}.Block"); - private static final Reflection.MethodInvoker getBlockByBlockData = Reflection.getTypedMethod(iBlockData, "getBlock", block); - private static final Reflection.MethodInvoker getBlockDataByBlock = Reflection.getTypedMethod(block, "getBlockData", iBlockData); + private static final Class iBlockData = Reflection.getClass("{nms.world.level.block.state}.IBlockData"); + private static final Class block = Reflection.getClass("{nms.world.level.block}.Block"); + private static final Reflection.MethodInvoker getBlockByBlockData = Reflection.getTypedMethod(iBlockData, null, block); + private static final Reflection.MethodInvoker getBlockDataByBlock = Reflection.getTypedMethod(block, null, iBlockData); private static final Class craftMagicNumbers = Reflection.getClass("{obc}.util.CraftMagicNumbers"); private static final Reflection.MethodInvoker getMaterialByBlock = Reflection.getTypedMethod(craftMagicNumbers, "getMaterial", Material.class, block); @@ -76,14 +76,14 @@ public class TechHider extends StateDependent { techhiders.put(mapChunkPacket, this::mapChunkHider); } if(Core.getVersion() > 12) { - Class blockBreakClass = Reflection.getClass("{nms}.PacketPlayOutBlockBreak"); + Class blockBreakClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutBlockBreak"); techhiders.put(blockBreakClass, blockBreakHiderGenerator(blockBreakClass)); } if(Core.getVersion() > 8){ - ProtocolAPI.setIncomingHandler(Reflection.getClass("{nms}.PacketPlayInUseItem"), (p, packet) -> p.getGameMode() == GameMode.SPECTATOR ? null : packet); + ProtocolAPI.setIncomingHandler(Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem"), (p, packet) -> p.getGameMode() == GameMode.SPECTATOR ? null : packet); } - ProtocolAPI.setIncomingHandler(Reflection.getClass("{nms}.PacketPlayInUseEntity"), (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(); } @@ -98,9 +98,10 @@ public class TechHider extends StateDependent { techhiders.keySet().forEach(ProtocolAPI::removeOutgoingHandler); } - private static final Class nbtTagCompound = Reflection.getClass("{nms}.NBTTagCompound"); - private static final Reflection.MethodInvoker nbtTagGetString = Reflection.getTypedMethod(nbtTagCompound, "getString", String.class, String.class); + private static final Class nbtTagCompound = Reflection.getClass("{nms.nbt}.NBTTagCompound"); + private static final Reflection.MethodInvoker nbtTagGetString = Reflection.getTypedMethod(nbtTagCompound, null, String.class, String.class); + //TODO private static final Class mapChunkPacket = Reflection.getClass("{nms}.PacketPlayOutMapChunk"); private static final UnaryOperator mapChunkCloner = ProtocolAPI.shallowCloneGenerator(mapChunkPacket); private static final Reflection.FieldAccessor mapChunkX = Reflection.getField(mapChunkPacket, int.class, 0); @@ -134,7 +135,8 @@ public class TechHider extends StateDependent { return packet; } - private static final Class multiBlockChangePacket = Reflection.getClass("{nms}.PacketPlayOutMultiBlockChange"); + private static final Class multiBlockChangePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutMultiBlockChange"); + //TODO private static final UnaryOperator multiBlockChangeCloner = ProtocolAPI.shallowCloneGenerator(multiBlockChangePacket); private static final Class chunkCoordinateIntPair = Reflection.getClass("{nms}.ChunkCoordIntPair"); private static final Reflection.FieldAccessor multiBlockChangeChunk = Reflection.getField(multiBlockChangePacket, chunkCoordinateIntPair, 0); diff --git a/FightSystem_Main/pom.xml b/FightSystem_Main/pom.xml index 2cd94da..a42f01d 100644 --- a/FightSystem_Main/pom.xml +++ b/FightSystem_Main/pom.xml @@ -92,6 +92,12 @@ 1.0 compile + + steamwar + FightSystem_18 + 1.0 + compile + steamwar FightSystem_Core diff --git a/pom.xml b/pom.xml index 35a72ae..aeee40f 100644 --- a/pom.xml +++ b/pom.xml @@ -57,10 +57,23 @@ FightSystem_12 FightSystem_14 FightSystem_15 + FightSystem_18 FightSystem_Core FightSystem_Main + + + minecraft-libraries + Minecraft Libraries + https://libraries.minecraft.net + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + steamwar From 6c0c6a7ae13d264309f2e724e0ce0a94c4822f53 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 14 Jan 2022 18:58:00 +0100 Subject: [PATCH 2/5] First steps to 1.18 wrappers Signed-off-by: Lixfel --- FightSystem_18/pom.xml | 6 ++ .../fightsystem/utils/BlockIdWrapper18.java | 86 +++++++++++++++++++ .../utils/CraftbukkitWrapper18.java | 72 ++++++++++++++++ 3 files changed, 164 insertions(+) create mode 100644 FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java create mode 100644 FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java diff --git a/FightSystem_18/pom.xml b/FightSystem_18/pom.xml index d854f64..edd0bde 100644 --- a/FightSystem_18/pom.xml +++ b/FightSystem_18/pom.xml @@ -37,6 +37,12 @@ 1.0 + + org.spigotmc + spigot-api + 1.18-R0.1-SNAPSHOT + provided + steamwar Spigot diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java new file mode 100644 index 0000000..83772aa --- /dev/null +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java @@ -0,0 +1,86 @@ +/* + 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 com.sk89q.worldedit.world.fluid.FluidTypes; +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 org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_18_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_18_R1.block.CraftBlock; + +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; + +public class BlockIdWrapper18 implements BlockIdWrapper.IBlockIdWrapper { + @Override + public int blockToId(Block block) { + return net.minecraft.world.level.block.Block.p.a(((CraftBlock)block).getNMS()); + } + + @Override + public void setBlock(World world, int x, int y, int z, int blockState) { + IBlockData blockData = Objects.requireNonNull(net.minecraft.world.level.block.Block.a(blockState)); + WorldServer cworld = ((CraftWorld)world).getHandle(); + BlockPosition pos = new BlockPosition(x, y, z); + cworld.removeTileEntity(pos); + cworld.setTypeAndData(pos, blockData, 1042); + cworld.getChunkProvider().flagDirty(pos); + } + + @Override + public Set getHiddenBlockIds() { + Set hiddenBlockIds = new HashSet<>(); + for(String tag : Config.HiddenBlocks){ + for(IBlockData data : IRegistry.k.get(new MinecraftKey(tag)).getStates().a()){ + hiddenBlockIds.add(net.minecraft.world.level.block.Block.getCombinedId(data)); + } + } + + if(Config.HiddenBlocks.contains("water")){ + Fluid water = FluidTypes.WATER.a(false); + for(IBlockData data : net.minecraft.world.level.block.Block.p){ + if(data.getFluid() == water){ + hiddenBlockIds.add(net.minecraft.world.level.block.Block.getCombinedId(data)); + } + } + } + + return hiddenBlockIds; + } + + @Override + public int getObfuscateWith() { + return net.minecraft.world.level.block.Block.i(IRegistry.k.get(new MinecraftKey(Config.ObfuscateWith)).getBlockData()); + } + + @Override + public Object getPose(boolean sneaking) { + return sneaking ? EntityPose.f : EntityPose.a; + } +} diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java new file mode 100644 index 0000000..8ca6b68 --- /dev/null +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java @@ -0,0 +1,72 @@ +/* + 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.fightsystem.fight.FightWorld; +import net.minecraft.world.level.chunk.Chunk; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_18_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.util.HashSet; +import java.util.Set; + +public class CraftbukkitWrapper18 implements CraftbukkitWrapper.ICraftbukkitWrapper { + + @Override + public void resetChunk(World world, World backup, int x, int z) { + net.minecraft.world.level.World w = ((CraftWorld) world).getHandle(); + Chunk chunk = w.d(x, z); + Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z); + + System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length); + w.tileEntityListTick.removeAll(chunk.tileEntities.values()); + if (!FightWorld.isPaper()) { + w.tileEntityList.removeAll(chunk.tileEntities.values()); + } + chunk.tileEntities.clear(); + chunk.tileEntities.putAll(backupChunk.tileEntities); + chunk.heightMap.clear(); + chunk.heightMap.putAll(backupChunk.heightMap); + } + + @Override + public void sendResourcePack(Player player, String pack, String sha1) { + ((CraftPlayer)player).getHandle().setResourcePack(pack, sha1); + } + + @Override + public float headRotation(Entity e) { + return ((CraftEntity)e).getHandle().getHeadRotation(); + } + + @Override + public boolean hasItems(ItemStack stack) { + Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).s().d()); + keys.remove("Enchantments"); + keys.remove("Damage"); + return !keys.isEmpty(); + } +} From 411e1ae539c9284c14cbbf8a378b47b3a9a7c57f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 14 Jan 2022 21:42:18 +0100 Subject: [PATCH 3/5] WIP 1.18 support Signed-off-by: Lixfel --- .../utils/FlatteningWrapper14.java | 4 +- FightSystem_18/pom.xml | 44 +++++++++++++++++ .../fightsystem/utils/BlockIdWrapper18.java | 47 ++++++++++--------- .../utils/CraftbukkitWrapper18.java | 30 ++++++------ .../fightsystem/utils/BountifulWrapper9.java | 12 ++--- FightSystem_Core/pom.xml | 6 +++ .../de/steamwar/fightsystem/fight/Fight.java | 10 ++-- .../fightsystem/listener/Recording.java | 4 +- .../steamwar/fightsystem/record/REntity.java | 35 +++++++++----- 9 files changed, 125 insertions(+), 67 deletions(-) diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/FlatteningWrapper14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/FlatteningWrapper14.java index 3cd74c0..0456dc9 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/FlatteningWrapper14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/FlatteningWrapper14.java @@ -120,9 +120,9 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper // field not present } - private static final Class entityTypes = Reflection.getClass("{nms}.EntityTypes"); + private static final Class entityTypes = Reflection.getClass("{nms.world.entity}.EntityTypes"); private static final Reflection.FieldAccessor spawnType = Reflection.getField(REntity.spawnPacket, entityTypes, 0); - private static final Object tnt = Reflection.getField(entityTypes, "TNT", entityTypes).get(null); + private static final Object tnt = Reflection.getField(entityTypes, "TNT", entityTypes).get(null); //TODO: Names not usable in 1.18 private static final Object arrow = Reflection.getField(entityTypes, "ARROW", entityTypes).get(null); private static final Object fireball = Reflection.getField(entityTypes, "FIREBALL", entityTypes).get(null); @Override diff --git a/FightSystem_18/pom.xml b/FightSystem_18/pom.xml index edd0bde..4788519 100644 --- a/FightSystem_18/pom.xml +++ b/FightSystem_18/pom.xml @@ -36,6 +36,44 @@ FightSystem_18 1.0 + + + + net.md-5 + specialsource-maven-plugin + 1.2.3 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:1.18.1-R0.1-SNAPSHOT:txt:maps-mojang + true + org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:1.18.1-R0.1-SNAPSHOT:csrg:maps-spigot + org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT:jar:remapped-obf + + + + + + + org.spigotmc @@ -43,6 +81,12 @@ 1.18-R0.1-SNAPSHOT provided + + com.mojang + datafixerupper + 4.0.26 + provided + steamwar Spigot diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java index 83772aa..4aa3ff9 100644 --- a/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java @@ -19,15 +19,15 @@ package de.steamwar.fightsystem.utils; -import com.sk89q.worldedit.world.fluid.FluidTypes; 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.core.BlockPos; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Pose; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_18_R1.CraftWorld; @@ -38,35 +38,36 @@ import java.util.Objects; import java.util.Set; public class BlockIdWrapper18 implements BlockIdWrapper.IBlockIdWrapper { + @Override public int blockToId(Block block) { - return net.minecraft.world.level.block.Block.p.a(((CraftBlock)block).getNMS()); + return net.minecraft.world.level.block.Block.getId(((CraftBlock)block).getNMS()); } @Override public void setBlock(World world, int x, int y, int z, int blockState) { - IBlockData blockData = Objects.requireNonNull(net.minecraft.world.level.block.Block.a(blockState)); - WorldServer cworld = ((CraftWorld)world).getHandle(); - BlockPosition pos = new BlockPosition(x, y, z); - cworld.removeTileEntity(pos); - cworld.setTypeAndData(pos, blockData, 1042); - cworld.getChunkProvider().flagDirty(pos); + BlockState blockData = Objects.requireNonNull(net.minecraft.world.level.block.Block.stateById(blockState)); + ServerLevel cworld = ((CraftWorld)world).getHandle(); + BlockPos pos = new BlockPos(x, y, z); + cworld.removeBlockEntity(pos); + cworld.setBlock(pos, blockData, 1042); + cworld.getChunkSource().blockChanged(pos); } @Override public Set getHiddenBlockIds() { Set hiddenBlockIds = new HashSet<>(); for(String tag : Config.HiddenBlocks){ - for(IBlockData data : IRegistry.k.get(new MinecraftKey(tag)).getStates().a()){ - hiddenBlockIds.add(net.minecraft.world.level.block.Block.getCombinedId(data)); + for(BlockState data : Registry.BLOCK.get(new ResourceLocation(tag)).getStateDefinition().getPossibleStates()){ + hiddenBlockIds.add(net.minecraft.world.level.block.Block.getId(data)); } } if(Config.HiddenBlocks.contains("water")){ - Fluid water = FluidTypes.WATER.a(false); - for(IBlockData data : net.minecraft.world.level.block.Block.p){ - if(data.getFluid() == water){ - hiddenBlockIds.add(net.minecraft.world.level.block.Block.getCombinedId(data)); + FluidState water = Fluids.WATER.defaultFluidState(); + for(BlockState data : net.minecraft.world.level.block.Block.BLOCK_STATE_REGISTRY) { + if(data.getFluidState() == water) { + hiddenBlockIds.add(net.minecraft.world.level.block.Block.getId(data)); } } } @@ -76,11 +77,11 @@ public class BlockIdWrapper18 implements BlockIdWrapper.IBlockIdWrapper { @Override public int getObfuscateWith() { - return net.minecraft.world.level.block.Block.i(IRegistry.k.get(new MinecraftKey(Config.ObfuscateWith)).getBlockData()); + return net.minecraft.world.level.block.Block.getId(Registry.BLOCK.get(new ResourceLocation(Config.ObfuscateWith)).defaultBlockState()); } @Override public Object getPose(boolean sneaking) { - return sneaking ? EntityPose.f : EntityPose.a; + return sneaking ? Pose.CROUCHING : Pose.STANDING; } } diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java index 8ca6b68..a666d06 100644 --- a/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java @@ -19,8 +19,7 @@ package de.steamwar.fightsystem.utils; -import de.steamwar.fightsystem.fight.FightWorld; -import net.minecraft.world.level.chunk.Chunk; +import net.minecraft.world.level.chunk.LevelChunk; import org.bukkit.World; import org.bukkit.craftbukkit.v1_18_R1.CraftWorld; import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity; @@ -37,34 +36,33 @@ public class CraftbukkitWrapper18 implements CraftbukkitWrapper.ICraftbukkitWrap @Override public void resetChunk(World world, World backup, int x, int z) { - net.minecraft.world.level.World w = ((CraftWorld) world).getHandle(); - Chunk chunk = w.d(x, z); - Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z); + net.minecraft.world.level.Level w = ((CraftWorld) world).getHandle(); + LevelChunk chunk = w.getChunk(x, z); + LevelChunk backupChunk = ((CraftWorld) backup).getHandle().getChunk(x, z); System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length); - w.tileEntityListTick.removeAll(chunk.tileEntities.values()); - if (!FightWorld.isPaper()) { - w.tileEntityList.removeAll(chunk.tileEntities.values()); - } - chunk.tileEntities.clear(); - chunk.tileEntities.putAll(backupChunk.tileEntities); - chunk.heightMap.clear(); - chunk.heightMap.putAll(backupChunk.heightMap); + + //w.blockEntityTickers.removeAll(chunk.tickersInLevel.values()); + //if (!FightWorld.isPaper()) { + // w.blockEntityTickersPending.removeAll(chunk.tickersInLevel.values()); + //} + //chunk.tickersInLevel.clear(); + //chunk.tickersInLevel.putAll(backupChunk.tickersInLevel); } @Override public void sendResourcePack(Player player, String pack, String sha1) { - ((CraftPlayer)player).getHandle().setResourcePack(pack, sha1); + ((CraftPlayer)player).getHandle().sendTexturePack(pack, sha1, true, null); } @Override public float headRotation(Entity e) { - return ((CraftEntity)e).getHandle().getHeadRotation(); + return ((CraftEntity)e).getHandle().getYHeadRot(); } @Override public boolean hasItems(ItemStack stack) { - Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).s().d()); + Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().getAllKeys()); keys.remove("Enchantments"); keys.remove("Damage"); return !keys.isEmpty(); diff --git a/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java b/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java index a21a46c..0f10e45 100644 --- a/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java +++ b/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java @@ -46,7 +46,7 @@ import java.util.UUID; public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { - private static final Class enumHand = Reflection.getClass("{nms}.EnumHand"); + private static final Class enumHand = Reflection.getClass("{nms.world}.EnumHand"); private static final Object mainHand = enumHand.getEnumConstants()[0]; private static final Reflection.FieldAccessor blockPlaceHand = Reflection.getField(Recording.blockPlacePacket, enumHand, 0); @@ -118,9 +118,9 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { } - private static final Class dataWatcherObject = Reflection.getClass("{nms}.DataWatcherObject"); - private static final Class dataWatcherRegistry = Reflection.getClass("{nms}.DataWatcherRegistry"); - private static final Class dataWatcherSerializer = Reflection.getClass("{nms}.DataWatcherSerializer"); + private static final Class dataWatcherObject = Reflection.getClass("{nms.network.syncher}.DataWatcherObject"); + private static final Class dataWatcherRegistry = Reflection.getClass("{nms.network.syncher}.DataWatcherRegistry"); + private static final Class dataWatcherSerializer = Reflection.getClass("{nms.network.syncher}.DataWatcherSerializer"); private static final Reflection.ConstructorInvoker dataWatcherObjectConstructor = Reflection.getConstructor(dataWatcherObject, int.class, dataWatcherSerializer); @Override public Object getDataWatcherObject(int index, Class type) { @@ -136,7 +136,7 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { throw new SecurityException("Could not find Serializer for " + type.getName()); } - private static final Class item = Reflection.getClass("{nms}.DataWatcher$Item"); + private static final Class item = Reflection.getClass("{nms.network.syncher}.DataWatcher$Item"); private static final Reflection.ConstructorInvoker itemConstructor = Reflection.getConstructor(item, dataWatcherObject, Object.class); @Override public Object getDataWatcherItem(Object dwo, Object value) { @@ -159,7 +159,7 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { spawnUUID.set(packet, uuid); } - private static final Class enumItemSlot = Reflection.getClass("{nms}.EnumItemSlot"); + private static final Class enumItemSlot = Reflection.getClass("{nms.world.entity}.EnumItemSlot"); private static final Reflection.FieldAccessor equipmentSlot = Reflection.getField(REntity.equipmentPacket, enumItemSlot, 0); private static final Object[] itemSlots = enumItemSlot.getEnumConstants(); @Override diff --git a/FightSystem_Core/pom.xml b/FightSystem_Core/pom.xml index f427dfc..2ce9c10 100644 --- a/FightSystem_Core/pom.xml +++ b/FightSystem_Core/pom.xml @@ -24,6 +24,12 @@ 1.18-R0.1-SNAPSHOT provided + + it.unimi.dsi + fastutil + 8.5.6 + provided + io.netty netty-all diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java index 6a1a3c6..a8e4236 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java @@ -130,19 +130,19 @@ public class Fight { } } - private static final Class playerInfoPacket = Reflection.getClass("{nms}.PacketPlayOutPlayerInfo"); + private static final Class playerInfoPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo"); private static final Reflection.ConstructorInvoker playerInfoConstructor = Reflection.getConstructor(playerInfoPacket); - private static final Class playerInfoActionClass = Reflection.getClass("{nms}.PacketPlayOutPlayerInfo$EnumPlayerInfoAction"); + private static final Class playerInfoActionClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$EnumPlayerInfoAction"); public static final Object addPlayer = playerInfoActionClass.getEnumConstants()[0]; private static final Reflection.FieldAccessor playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0); private static final Object updateGamemode = playerInfoActionClass.getEnumConstants()[1]; public static final Object removePlayer = playerInfoActionClass.getEnumConstants()[4]; private static final Reflection.FieldAccessor playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0); - private static final Class playerInfoDataClass = Reflection.getClass("{nms}.PacketPlayOutPlayerInfo$PlayerInfoData"); - private static final Class enumGamemode = Reflection.getClass(Core.getVersion() > 9 ? "{nms}.EnumGamemode" : "{nms}.WorldSettings$EnumGamemode"); + private static final Class playerInfoDataClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$PlayerInfoData"); + private static final Class enumGamemode = Reflection.getClass(Core.getVersion() > 9 ? "{nms.world.level}.EnumGamemode" : "{nms}.WorldSettings$EnumGamemode"); public static final Object creative = enumGamemode.getEnumConstants()[2]; private static final Object spectator = enumGamemode.getEnumConstants()[4]; - private static final Class iChatBaseComponent = Reflection.getClass("{nms}.IChatBaseComponent"); + private static final Class iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent"); private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClass, playerInfoPacket, GameProfile.class, int.class, enumGamemode, iChatBaseComponent); public static void pseudoSpectator(Player player, boolean enable) { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java index 1d2f412..0b158b6 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java @@ -115,7 +115,7 @@ public class Recording implements Listener { }, 1, 1); } - private static final Class blockDigPacket = Reflection.getClass("{nms}.PacketPlayInBlockDig"); + private static final Class blockDigPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockDig"); private static final Class playerDigType = blockDigPacket.getDeclaredClasses()[0]; private static final Reflection.FieldAccessor blockDigType = Reflection.getField(blockDigPacket, playerDigType, 0); private static final Object releaseUseItem = playerDigType.getEnumConstants()[5]; @@ -125,7 +125,7 @@ public class Recording implements Listener { return packet; } - public static final Class blockPlacePacket = Reflection.getClass("{nms}.PacketPlayInBlockPlace"); + public static final Class blockPlacePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockPlace"); private Object blockPlace(Player p, Object packet) { boolean mainHand = BountifulWrapper.impl.mainHand(packet); if(BountifulWrapper.impl.bowInHand(mainHand, p)) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/REntity.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/REntity.java index 2523cf0..3c703d8 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/REntity.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/REntity.java @@ -31,6 +31,8 @@ import de.steamwar.fightsystem.utils.BountifulWrapper; import de.steamwar.fightsystem.utils.FlatteningWrapper; import de.steamwar.fightsystem.utils.ProtocolAPI; import de.steamwar.sql.SteamwarUser; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntList; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.EntityType; @@ -174,7 +176,7 @@ public class REntity { ProtocolAPI.broadcastPacket(getHeadRotationPacket()); } - private static final Class animationPacket = Reflection.getClass("{nms}.PacketPlayOutAnimation"); + private static final Class animationPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutAnimation"); private static final Reflection.ConstructorInvoker animationConstructor = Reflection.getConstructor(animationPacket); private static final Reflection.FieldAccessor animationEntity = Reflection.getField(animationPacket, int.class, 0); private static final Reflection.FieldAccessor animationAnimation = Reflection.getField(animationPacket, int.class, 1); @@ -185,7 +187,7 @@ public class REntity { ProtocolAPI.broadcastPacket(packet); } - private static final Class velocityPacket = Reflection.getClass("{nms}.PacketPlayOutEntityVelocity"); + private static final Class velocityPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityVelocity"); private static final Reflection.ConstructorInvoker velocityConstructor = Reflection.getConstructor(velocityPacket); private static final Reflection.FieldAccessor velocityEntity = Reflection.getField(velocityPacket, int.class, 0); private static final Reflection.FieldAccessor velocityX = Reflection.getField(velocityPacket, int.class, 1); @@ -200,7 +202,7 @@ public class REntity { ProtocolAPI.broadcastPacket(packet); } - private static final Class statusPacket = Reflection.getClass("{nms}.PacketPlayOutEntityStatus"); + private static final Class statusPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityStatus"); private static final Reflection.ConstructorInvoker statusConstructor = Reflection.getConstructor(statusPacket); private static final Reflection.FieldAccessor statusEntity = Reflection.getField(statusPacket, int.class, 0); private static final Reflection.FieldAccessor statusStatus = Reflection.getField(statusPacket, byte.class, 0); @@ -248,9 +250,16 @@ public class REntity { entities.remove(internalId); } - private static final Class destroyPacket = Reflection.getClass("{nms}.PacketPlayOutEntityDestroy"); + private static final Class destroyPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityDestroy"); private static final Reflection.ConstructorInvoker destroyConstructor = Reflection.getConstructor(destroyPacket); - private static final Reflection.FieldAccessor destroyEntities = Reflection.getField(destroyPacket, int[].class, 0); + private static final Reflection.FieldAccessor destroyEntities; + static { + if(Core.getVersion() > 15) + destroyEntities = Reflection.getField(destroyPacket, IntList.class, 0); + else + destroyEntities = Reflection.getField(destroyPacket, int[].class, 0); + } + private void broadcastDeath(){ if(entityType == EntityType.PLAYER){ ProtocolAPI.broadcastPacket(Fight.playerInfoPacket(Fight.removePlayer, new GameProfile(uuid, name), Fight.creative)); @@ -258,7 +267,7 @@ public class REntity { } Object packet = destroyConstructor.invoke(); - destroyEntities.set(packet, new int[]{entityId}); + destroyEntities.set(packet, Core.getVersion() > 15 ? new IntArrayList(new int[]{entityId}) : new int[]{entityId}); ProtocolAPI.broadcastPacket(packet); } @@ -266,7 +275,7 @@ public class REntity { return (int)(Math.max(-3.9, Math.min(value, 3.9)) * 8000); } - private static final Class metadataPacket = Reflection.getClass("{nms}.PacketPlayOutEntityMetadata"); + private static final Class metadataPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityMetadata"); private static final Reflection.ConstructorInvoker metadataConstructor = Reflection.getConstructor(metadataPacket); private static final Reflection.FieldAccessor metadataEntity = Reflection.getField(metadataPacket, int.class, 0); private static final Reflection.FieldAccessor metadataMetadata = Reflection.getField(metadataPacket, List.class, 0); @@ -277,7 +286,7 @@ public class REntity { return packet; } - public static final Class teleportPacket = Reflection.getClass("{nms}.PacketPlayOutEntityTeleport"); + public static final Class teleportPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityTeleport"); private static final Reflection.ConstructorInvoker teleportConstructor = Reflection.getConstructor(teleportPacket); private static final Reflection.FieldAccessor teleportEntity = Reflection.getField(teleportPacket, int.class, 0); private static final Reflection.FieldAccessor teleportYaw = Reflection.getField(teleportPacket, byte.class, 0); @@ -291,7 +300,7 @@ public class REntity { return packet; } - private static final Class headRotationPacket = Reflection.getClass("{nms}.PacketPlayOutEntityHeadRotation"); + private static final Class headRotationPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityHeadRotation"); private static final Reflection.ConstructorInvoker headRotationConstructor = Reflection.getConstructor(headRotationPacket); private static final Reflection.FieldAccessor headRotationEntity = Reflection.getField(headRotationPacket, int.class, 0); private static final Reflection.FieldAccessor headRotationYaw = Reflection.getField(headRotationPacket, byte.class, 0); @@ -302,7 +311,7 @@ public class REntity { return packet; } - public static final Class spawnPacket = Reflection.getClass("{nms}.PacketPlayOutSpawnEntity"); + public static final Class spawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutSpawnEntity"); private static final Reflection.ConstructorInvoker spawnConstructor = Reflection.getConstructor(spawnPacket); private static final Reflection.FieldAccessor spawnEntity = Reflection.getField(spawnPacket, int.class, 0); private Object getSpawnEntityPacket(){ @@ -313,11 +322,11 @@ public class REntity { return packet; } - public static final Class equipmentPacket = Reflection.getClass("{nms}.PacketPlayOutEntityEquipment"); + public static final Class equipmentPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityEquipment"); private static final Reflection.ConstructorInvoker equipmentConstructor = Reflection.getConstructor(equipmentPacket); private static final Reflection.FieldAccessor equipmentEntity = Reflection.getField(equipmentPacket, int.class, 0); private static final Class itemStack = Reflection.getClass("{nms}.ItemStack"); - private static final Reflection.FieldAccessor equipmentStack = Reflection.getField(equipmentPacket, itemStack, 0); + private static final Reflection.FieldAccessor equipmentStack = Reflection.getField(equipmentPacket, itemStack, 0); //TODO: Changed in 1.18 private static final Class craftItemStack = Reflection.getClass("{obc}.inventory.CraftItemStack"); private static final Reflection.MethodInvoker asNMSCopy = Reflection.getTypedMethod(craftItemStack, "asNMSCopy", itemStack, ItemStack.class); private Object getEquipmentPacket(String slot, ItemStack stack){ @@ -332,7 +341,7 @@ public class REntity { return Fight.playerInfoPacket(Fight.addPlayer, new GameProfile(uuid, name), Fight.creative); } - public static final Class namedSpawnPacket = Reflection.getClass("{nms}.PacketPlayOutNamedEntitySpawn"); + public static final Class namedSpawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutNamedEntitySpawn"); private static final Reflection.ConstructorInvoker namedSpawnConstructor = Reflection.getConstructor(namedSpawnPacket); private static final Reflection.FieldAccessor namedSpawnEntity = Reflection.getField(namedSpawnPacket, int.class, 0); private static final Reflection.FieldAccessor namedSpawnUUID = Reflection.getField(namedSpawnPacket, UUID.class, 0); From 9519329505732ef830ca743494157b70947458e4 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 2 Feb 2022 23:58:45 +0100 Subject: [PATCH 4/5] Full untested 1.18 implementation Signed-off-by: Lixfel --- .../fightsystem/utils/ProtocolWrapper12.java | 49 +++++ FightSystem_14/pom.xml | 5 + .../utils/FlatteningWrapper14.java | 23 --- .../fightsystem/utils/TechHider14.java | 9 +- FightSystem_18/pom.xml | 44 +---- .../fightsystem/utils/BlockIdWrapper18.java | 48 ++--- .../utils/CraftbukkitWrapper18.java | 23 +-- .../fightsystem/utils/ProtocolWrapper18.java | 117 ++++++++++++ .../fightsystem/utils/TechHider18.java | 167 ++++++++++++++++++ .../fightsystem/utils/BountifulWrapper8.java | 23 --- .../fightsystem/utils/FlatteningWrapper8.java | 18 -- .../fightsystem/utils/ProtocolWrapper8.java | 142 +++++++++++++++ .../fightsystem/utils/TechHider8.java | 16 +- FightSystem_9/pom.xml | 5 + .../fightsystem/utils/BountifulWrapper9.java | 26 --- .../fightsystem/utils/TechHider9.java | 41 ++++- .../de/steamwar/fightsystem/fight/Fight.java | 4 +- .../steamwar/fightsystem/record/REntity.java | 46 ++--- .../fightsystem/utils/BountifulWrapper.java | 1 - .../fightsystem/utils/FlatteningWrapper.java | 2 - .../fightsystem/utils/ProtocolAPI.java | 16 +- .../fightsystem/utils/ProtocolWrapper.java | 41 +++++ .../steamwar/fightsystem/utils/TechHider.java | 129 +++----------- 23 files changed, 666 insertions(+), 329 deletions(-) create mode 100644 FightSystem_12/src/de/steamwar/fightsystem/utils/ProtocolWrapper12.java create mode 100644 FightSystem_18/src/de/steamwar/fightsystem/utils/ProtocolWrapper18.java create mode 100644 FightSystem_18/src/de/steamwar/fightsystem/utils/TechHider18.java create mode 100644 FightSystem_8/src/de/steamwar/fightsystem/utils/ProtocolWrapper8.java create mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/utils/ProtocolWrapper.java diff --git a/FightSystem_12/src/de/steamwar/fightsystem/utils/ProtocolWrapper12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/ProtocolWrapper12.java new file mode 100644 index 0000000..3c376b4 --- /dev/null +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/ProtocolWrapper12.java @@ -0,0 +1,49 @@ +/* + 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 com.comphenix.tinyprotocol.Reflection; +import de.steamwar.fightsystem.Config; +import org.bukkit.entity.Player; + +import java.util.function.BiFunction; +import java.util.function.UnaryOperator; + +public class ProtocolWrapper12 extends ProtocolWrapper8 { + + @Override + public BiFunction blockBreakHiderGenerator(Class blockBreakPacket){ + UnaryOperator blockBreakCloner = ProtocolAPI.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)))) + return packet; + + if(Config.HiddenBlocks.contains(TechHider.getMaterialByIBlockData(blockBreakBlockData.get(packet)).name().toLowerCase())){ + packet = blockBreakCloner.apply(packet); + blockBreakBlockData.set(packet, TechHider.obfuscateIBlockData); + } + return packet; + }; + } +} diff --git a/FightSystem_14/pom.xml b/FightSystem_14/pom.xml index ad025b7..7b82230 100644 --- a/FightSystem_14/pom.xml +++ b/FightSystem_14/pom.xml @@ -37,5 +37,10 @@ FightSystem_Core 1.0 + + steamwar + FightSystem_9 + 1.0 + \ No newline at end of file diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/FlatteningWrapper14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/FlatteningWrapper14.java index 0456dc9..239c774 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/FlatteningWrapper14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/FlatteningWrapper14.java @@ -19,15 +19,12 @@ package de.steamwar.fightsystem.utils; -import com.comphenix.tinyprotocol.Reflection; -import de.steamwar.fightsystem.record.REntity; import org.bukkit.DyeColor; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Waterlogged; -import org.bukkit.entity.EntityType; import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BlockDataMeta; @@ -119,24 +116,4 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper public void setNamedSpawnPacketDataWatcher(Object packet) { // field not present } - - private static final Class entityTypes = Reflection.getClass("{nms.world.entity}.EntityTypes"); - private static final Reflection.FieldAccessor spawnType = Reflection.getField(REntity.spawnPacket, entityTypes, 0); - private static final Object tnt = Reflection.getField(entityTypes, "TNT", entityTypes).get(null); //TODO: Names not usable in 1.18 - private static final Object arrow = Reflection.getField(entityTypes, "ARROW", entityTypes).get(null); - private static final Object fireball = Reflection.getField(entityTypes, "FIREBALL", entityTypes).get(null); - @Override - public void setSpawnPacketType(Object packet, EntityType type) { - switch(type) { - case PRIMED_TNT: - spawnType.set(packet, tnt); - break; - case ARROW: - spawnType.set(packet, arrow); - break; - case FIREBALL: - spawnType.set(packet, fireball); - break; - } - } } diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider14.java index a391a50..e5674b6 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider14.java @@ -24,16 +24,11 @@ import io.netty.buffer.UnpooledByteBufAllocator; import java.nio.ByteBuffer; import java.nio.LongBuffer; -import java.util.Set; -import java.util.function.BiFunction; -public class TechHider14 implements BiFunction { - - private final Set hiddenBlockIds = BlockIdWrapper.impl.getHiddenBlockIds(); - private final int obfuscateWith = BlockIdWrapper.impl.getObfuscateWith(); +public class TechHider14 extends TechHider9 { @Override - public byte[] apply(byte[] data, Integer primaryBitMask) { + protected byte[] dataHider(byte[] data, Integer primaryBitMask) { ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100); int i = 0; diff --git a/FightSystem_18/pom.xml b/FightSystem_18/pom.xml index 4788519..4dec64d 100644 --- a/FightSystem_18/pom.xml +++ b/FightSystem_18/pom.xml @@ -36,44 +36,6 @@ FightSystem_18 1.0 - - - - net.md-5 - specialsource-maven-plugin - 1.2.3 - - - package - - remap - - remap-obf - - org.spigotmc:minecraft-server:1.18.1-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:1.18.1-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT:jar:remapped-obf - - - - - - - org.spigotmc @@ -87,6 +49,12 @@ 4.0.26 provided + + io.netty + netty-all + 4.1.68.Final + provided + steamwar Spigot diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java index 4aa3ff9..59811e5 100644 --- a/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java @@ -20,14 +20,14 @@ package de.steamwar.fightsystem.utils; import de.steamwar.fightsystem.Config; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Registry; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.entity.Pose; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.FluidState; -import net.minecraft.world.level.material.Fluids; +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_R1.CraftWorld; @@ -41,33 +41,33 @@ public class BlockIdWrapper18 implements BlockIdWrapper.IBlockIdWrapper { @Override public int blockToId(Block block) { - return net.minecraft.world.level.block.Block.getId(((CraftBlock)block).getNMS()); + return net.minecraft.world.level.block.Block.i(((CraftBlock)block).getNMS()); } @Override public void setBlock(World world, int x, int y, int z, int blockState) { - BlockState blockData = Objects.requireNonNull(net.minecraft.world.level.block.Block.stateById(blockState)); - ServerLevel cworld = ((CraftWorld)world).getHandle(); - BlockPos pos = new BlockPos(x, y, z); - cworld.removeBlockEntity(pos); - cworld.setBlock(pos, blockData, 1042); - cworld.getChunkSource().blockChanged(pos); + IBlockData blockData = Objects.requireNonNull(net.minecraft.world.level.block.Block.a(blockState)); + WorldServer cworld = ((CraftWorld)world).getHandle(); + BlockPosition pos = new BlockPosition(x, y, z); + cworld.m(pos); + cworld.a(pos, blockData, 1042); + cworld.k().a(pos); } @Override public Set getHiddenBlockIds() { Set hiddenBlockIds = new HashSet<>(); for(String tag : Config.HiddenBlocks){ - for(BlockState data : Registry.BLOCK.get(new ResourceLocation(tag)).getStateDefinition().getPossibleStates()){ - hiddenBlockIds.add(net.minecraft.world.level.block.Block.getId(data)); + for(IBlockData data : IRegistry.X.a(new MinecraftKey(tag)).m().a()){ + hiddenBlockIds.add(net.minecraft.world.level.block.Block.i(data)); } } if(Config.HiddenBlocks.contains("water")){ - FluidState water = Fluids.WATER.defaultFluidState(); - for(BlockState data : net.minecraft.world.level.block.Block.BLOCK_STATE_REGISTRY) { - if(data.getFluidState() == water) { - hiddenBlockIds.add(net.minecraft.world.level.block.Block.getId(data)); + Fluid water = FluidTypes.c.h(); + for(IBlockData data : net.minecraft.world.level.block.Block.p) { + if(data.n() == water) { + hiddenBlockIds.add(net.minecraft.world.level.block.Block.i(data)); } } } @@ -76,12 +76,12 @@ public class BlockIdWrapper18 implements BlockIdWrapper.IBlockIdWrapper { } @Override - public int getObfuscateWith() { - return net.minecraft.world.level.block.Block.getId(Registry.BLOCK.get(new ResourceLocation(Config.ObfuscateWith)).defaultBlockState()); + public int getObfuscateWith() { //ResourceLocation, DefaultedRegistry + return net.minecraft.world.level.block.Block.i(IRegistry.X.a(new MinecraftKey(Config.ObfuscateWith)).n()); } @Override public Object getPose(boolean sneaking) { - return sneaking ? Pose.CROUCHING : Pose.STANDING; + return sneaking ? EntityPose.f : EntityPose.a; } } diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java index a666d06..617d61f 100644 --- a/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.utils; -import net.minecraft.world.level.chunk.LevelChunk; +import net.minecraft.world.level.chunk.Chunk; import org.bukkit.World; import org.bukkit.craftbukkit.v1_18_R1.CraftWorld; import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity; @@ -36,33 +36,26 @@ public class CraftbukkitWrapper18 implements CraftbukkitWrapper.ICraftbukkitWrap @Override public void resetChunk(World world, World backup, int x, int z) { - net.minecraft.world.level.Level w = ((CraftWorld) world).getHandle(); - LevelChunk chunk = w.getChunk(x, z); - LevelChunk backupChunk = ((CraftWorld) backup).getHandle().getChunk(x, z); + net.minecraft.world.level.World w = ((CraftWorld) world).getHandle(); + Chunk chunk = w.d(x, z); + Chunk backupChunk = ((CraftWorld) backup).getHandle().d(x, z); - System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length); - - //w.blockEntityTickers.removeAll(chunk.tickersInLevel.values()); - //if (!FightWorld.isPaper()) { - // w.blockEntityTickersPending.removeAll(chunk.tickersInLevel.values()); - //} - //chunk.tickersInLevel.clear(); - //chunk.tickersInLevel.putAll(backupChunk.tickersInLevel); + System.arraycopy(backupChunk.d(), 0, chunk.d(), 0, chunk.d().length); } @Override public void sendResourcePack(Player player, String pack, String sha1) { - ((CraftPlayer)player).getHandle().sendTexturePack(pack, sha1, true, null); + ((CraftPlayer)player).getHandle().a(pack, sha1, true, null); } @Override public float headRotation(Entity e) { - return ((CraftEntity)e).getHandle().getYHeadRot(); + return ((CraftEntity)e).getHandle().ce(); } @Override public boolean hasItems(ItemStack stack) { - Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().getAllKeys()); + Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).s().d()); keys.remove("Enchantments"); keys.remove("Damage"); return !keys.isEmpty(); diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/ProtocolWrapper18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/ProtocolWrapper18.java new file mode 100644 index 0000000..a47d824 --- /dev/null +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/ProtocolWrapper18.java @@ -0,0 +1,117 @@ +/* + 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 com.comphenix.tinyprotocol.Reflection; +import com.mojang.datafixers.util.Pair; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.record.REntity; +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 { + + private static final Reflection.FieldAccessor equipmentStack = Reflection.getField(REntity.equipmentPacket, List.class, 0); + @Override + public void setEquipmentPacketStack(Object packet, String slot, Object stack) { + equipmentStack.set(packet, Collections.singletonList(new Pair<>(getSlot(slot), stack))); + } + + private static final Reflection.FieldAccessor spawnType = Reflection.getField(REntity.spawnPacket, EntityTypes.class, 0); + @Override + public void setSpawnPacketType(Object packet, EntityType type) { + switch(type) { + case PRIMED_TNT: + spawnType.set(packet, EntityTypes.as); + break; + case ARROW: + spawnType.set(packet, EntityTypes.d); + break; + case FIREBALL: + spawnType.set(packet, EntityTypes.S); + break; + } + } + + private static final Class enumItemSlot = Reflection.getClass("{nms.world.entity}.EnumItemSlot"); + private static final Object[] itemSlots = enumItemSlot.getEnumConstants(); + private static Object getSlot(String slot) { + switch(slot){ + case "HEAD": + return itemSlots[5]; + case "CHEST": + return itemSlots[4]; + case "LEGS": + return itemSlots[3]; + case "FEET": + return itemSlots[2]; + case "OFFHAND": + return itemSlots[1]; + case "MAINHAND": + default: + return itemSlots[0]; + } + } + + private static final Class sectionPosition = Reflection.getClass("{nms.core}.SectionPosition"); + private static final Reflection.FieldAccessor multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, sectionPosition, 0); + private static final Class iBlockDataArray = Reflection.getClass("[L{nms.world.level.block.state}.IBlockData;"); + private static final Reflection.FieldAccessor multiBlockChangeBlocks = Reflection.getField(TechHider.multiBlockChangePacket, iBlockDataArray, 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; + + Object modpacket = TechHider.multiBlockChangeCloner.apply(packet); + multiBlockChangeBlocks.set(modpacket, iBlockDataArrayCloner.apply(multiBlockChangeBlocks.get(modpacket), block -> Config.HiddenBlocks.contains(TechHider.getMaterialByIBlockData(block).name().toLowerCase()) ? TechHider.obfuscateIBlockData : block)); + return modpacket; + } + + 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(!Config.HiddenBlocks.contains(TechHider.getMaterialByIBlockData(breakPacket.c()).name().toLowerCase())) + return packet; + + return new PacketPlayOutBlockBreak(breakPacket.b(), (IBlockData) TechHider.obfuscateIBlockData, breakPacket.d(), breakPacket.a()); + }; + } +} diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/TechHider18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/TechHider18.java new file mode 100644 index 0000000..33362a1 --- /dev/null +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/TechHider18.java @@ -0,0 +1,167 @@ +/* + 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 com.comphenix.tinyprotocol.Reflection; +import de.steamwar.fightsystem.Config; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData; +import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; +import net.minecraft.world.entity.EntityTypes; +import org.bukkit.World; +import org.bukkit.entity.Player; + +import java.nio.ByteBuffer; +import java.nio.LongBuffer; +import java.util.List; +import java.util.Set; +import java.util.function.IntFunction; +import java.util.function.UnaryOperator; +import java.util.stream.Collectors; + +public class TechHider18 implements TechHider.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 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"); + private static final Reflection.FieldAccessor entityType = Reflection.getField(tileEntity, EntityTypes.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))) + return packet; + + packet = chunkPacketCloner.apply(packet); + Object data = chunkDataCloner.apply(chunkData.get(packet)); + + tileEntities.set(packet, ((List)tileEntities.get(packet)).stream().filter( + tile -> Config.HiddenBlockEntities.contains(entityType.get(tile).i()) //TODO: i()? + ).collect(Collectors.toList())); + + World world = p.getWorld(); + int sections = (world.getMaxHeight() - world.getMinHeight()) / 16; + System.out.println(sections); //TODO + dataField.set(data, dataHider(dataField.get(data), sections)); + + chunkData.set(packet, data); + return packet; + } + + private byte[] dataHider(byte[] data, int sections) { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100); + int i = 0; + + while(sections-- > 0) { + i = containerWalker(data, buffer, i, 15, blockId -> hiddenBlockIds.contains(blockId) ? obfuscateWith : blockId, (curI, dataArrayLength, bitsPerBlock) -> { + if(bitsPerBlock < 15) { + buffer.writeBytes(data, curI, dataArrayLength * 8); + } else { + ByteBuffer source = ByteBuffer.wrap(data, curI, dataArrayLength * 8); + 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); + } + } + + for (long l : values.backing) + 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, Region.TriConsumer dataArray) { + byte bitsPerBlock = data[i++]; + buffer.writeByte(bitsPerBlock); + + if(bitsPerBlock < globalPalette) { + int paletteLength = TechHider.readVarInt(data, i); + int paletteLengthLength = TechHider.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 dataArrayLength = TechHider.readVarInt(data, i); + int dataArrayLengthLength = TechHider.readVarIntLength(data, i); + buffer.writeBytes(data, i, dataArrayLengthLength); + i += dataArrayLengthLength; + + dataArray.accept(i, dataArrayLength, bitsPerBlock); + i += dataArrayLength * 8; + + return i; + } + + private static final class VariableValueArray { + private final long[] backing; + private final int bitsPerValue; + private final long valueMask; + private final int valuesPerLong; + + 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; + this.valuesPerLong = 64 / bitsPerEntry; + } + + public int get(int index) { + return (int)((backing[index / valuesPerLong] >> ((index % valuesPerLong) * bitsPerValue)) & valueMask); + } + + public void set(int index, int value) { + int i0 = index / valuesPerLong; + int i1 = index % valuesPerLong; + + backing[i0] = backing[i0] & ~(this.valueMask << i1) | (value & valueMask) << i1; + } + } +} diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java index dc31f36..2a838a6 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java @@ -128,29 +128,6 @@ public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper { // field not present } - private static final Reflection.FieldAccessor equipmentSlot = Reflection.getField(REntity.equipmentPacket, int.class, 1); - @Override - public void setEquipmentPacketSlot(Object packet, String slot) { - switch(slot){ - case "HEAD": - equipmentSlot.set(packet, 4); - break; - case "CHEST": - equipmentSlot.set(packet, 3); - break; - case "LEGS": - equipmentSlot.set(packet, 2); - break; - case "FEET": - equipmentSlot.set(packet, 1); - break; - case "MAINHAND": - case "OFFHAND": - default: - equipmentSlot.set(packet, 0); - } - } - private final Set seesDragon = new HashSet<>(); private final PacketPlayOutSpawnEntityLiving spawnDragon; private final int spawnDragonId; diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/FlatteningWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/FlatteningWrapper8.java index e672541..95fd263 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/FlatteningWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/FlatteningWrapper8.java @@ -20,13 +20,11 @@ package de.steamwar.fightsystem.utils; import com.comphenix.tinyprotocol.Reflection; -import de.steamwar.core.Core; import de.steamwar.fightsystem.record.REntity; import org.bukkit.DyeColor; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.entity.EntityType; import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -90,20 +88,4 @@ public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper public void setNamedSpawnPacketDataWatcher(Object packet) { namedSpawnDataWatcher.set(packet, dataWatcherConstructor.invoke((Object) null)); } - - private static final Reflection.FieldAccessor spawnType = Reflection.getField(REntity.spawnPacket, int.class, Core.getVersion() > 8 ? 6 : 9); - @Override - public void setSpawnPacketType(Object packet, EntityType type) { - switch(type) { - case PRIMED_TNT: - spawnType.set(packet, 50); - break; - case ARROW: - spawnType.set(packet, 60); - break; - case FIREBALL: - spawnType.set(packet, 63); - break; - } - } } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/ProtocolWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/ProtocolWrapper8.java new file mode 100644 index 0000000..91d9646 --- /dev/null +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/ProtocolWrapper8.java @@ -0,0 +1,142 @@ +/* + 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 com.comphenix.tinyprotocol.Reflection; +import de.steamwar.core.Core; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.record.REntity; +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 { + + private static final Reflection.FieldAccessor equipmentSlot; + private static final Object[] itemSlots; + static { + if(Core.getVersion() == 8) { + equipmentSlot = Reflection.getField(REntity.equipmentPacket, int.class, 1); + itemSlots = new Integer[]{0, 0, 1, 2, 3, 4}; + } else { + Class enumItemSlot = Reflection.getClass("{nms.world.entity}.EnumItemSlot"); + equipmentSlot = Reflection.getField(REntity.equipmentPacket, enumItemSlot, 0); + itemSlots = enumItemSlot.getEnumConstants(); + } + } + + private static final Reflection.FieldAccessor equipmentStack = Reflection.getField(REntity.equipmentPacket, REntity.itemStack, 0); + @Override + public void setEquipmentPacketStack(Object packet, String slot, Object stack) { + switch(slot){ + case "HEAD": + equipmentSlot.set(packet, itemSlots[5]); + break; + case "CHEST": + equipmentSlot.set(packet, itemSlots[4]); + break; + case "LEGS": + equipmentSlot.set(packet, itemSlots[3]); + break; + case "FEET": + equipmentSlot.set(packet, itemSlots[2]); + break; + case "OFFHAND": + equipmentSlot.set(packet, itemSlots[1]); + break; + case "MAINHAND": + default: + equipmentSlot.set(packet, itemSlots[0]); + } + equipmentStack.set(packet, stack); + } + + private static final Reflection.FieldAccessor spawnType; + private static final Object tnt; + private static final Object arrow; + private static final Object fireball; + static { + if(Core.getVersion() < 14) { + spawnType = Reflection.getField(REntity.spawnPacket, int.class, Core.getVersion() > 8 ? 6 : 9); + tnt = 50; + arrow = 60; + fireball = 63; + } else { + Class entityTypes = Reflection.getClass("{nms.world.entity}.EntityTypes"); + spawnType = Reflection.getField(REntity.spawnPacket, entityTypes, 0); + tnt = Reflection.getField(entityTypes, "TNT", entityTypes).get(null); + arrow = Reflection.getField(entityTypes, "ARROW", entityTypes).get(null); + fireball = Reflection.getField(entityTypes, "FIREBALL", entityTypes).get(null); + } + } + @Override + public void setSpawnPacketType(Object packet, EntityType type) { + switch(type) { + case PRIMED_TNT: + spawnType.set(packet, tnt); + break; + case ARROW: + spawnType.set(packet, arrow); + break; + case FIREBALL: + spawnType.set(packet, fireball); + break; + } + } + + 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(Config.HiddenBlocks.contains(TechHider.getMaterialByIBlockData(multiBlockChangeInfoBlock.get(mbci)).name().toLowerCase())) + 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; + } +} diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/TechHider8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/TechHider8.java index 39aaecc..d299c3d 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/TechHider8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/TechHider8.java @@ -19,13 +19,19 @@ package de.steamwar.fightsystem.utils; -import java.util.function.BiFunction; +import com.comphenix.tinyprotocol.Reflection; +import org.bukkit.entity.Player; -public class TechHider8 implements BiFunction { +public class TechHider8 implements TechHider.ChunkHider { + + protected static final Class mapChunkPacket = Reflection.getClass("{nms}.PacketPlayOutMapChunk"); + @Override + public Class mapChunkPacket() { + return mapChunkPacket; + } @Override - public byte[] apply(byte[] data, Integer primaryBitMask) { - // No implementation availible - return data; + public Object mapChunkHider(Player p, Object packet) { + return packet; } } diff --git a/FightSystem_9/pom.xml b/FightSystem_9/pom.xml index 8cf317c..1dd055b 100644 --- a/FightSystem_9/pom.xml +++ b/FightSystem_9/pom.xml @@ -23,6 +23,11 @@ FightSystem_Core 1.0 + + steamwar + FightSystem_8 + 1.0 + steamwar WorldEdit diff --git a/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java b/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java index 0f10e45..8e86735 100644 --- a/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java +++ b/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java @@ -159,32 +159,6 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { spawnUUID.set(packet, uuid); } - private static final Class enumItemSlot = Reflection.getClass("{nms.world.entity}.EnumItemSlot"); - private static final Reflection.FieldAccessor equipmentSlot = Reflection.getField(REntity.equipmentPacket, enumItemSlot, 0); - private static final Object[] itemSlots = enumItemSlot.getEnumConstants(); - @Override - public void setEquipmentPacketSlot(Object packet, String slot) { - switch(slot){ - case "HEAD": - equipmentSlot.set(packet, itemSlots[5]); - break; - case "CHEST": - equipmentSlot.set(packet, itemSlots[4]); - break; - case "LEGS": - equipmentSlot.set(packet, itemSlots[3]); - break; - case "FEET": - equipmentSlot.set(packet, itemSlots[2]); - break; - case "OFFHAND": - equipmentSlot.set(packet, itemSlots[1]); - break; - case "MAINHAND": - default: - equipmentSlot.set(packet, itemSlots[0]); - } - } private final Map barMap = new HashMap<>(); @Override diff --git a/FightSystem_9/src/de/steamwar/fightsystem/utils/TechHider9.java b/FightSystem_9/src/de/steamwar/fightsystem/utils/TechHider9.java index e1f6bef..c07bcb2 100644 --- a/FightSystem_9/src/de/steamwar/fightsystem/utils/TechHider9.java +++ b/FightSystem_9/src/de/steamwar/fightsystem/utils/TechHider9.java @@ -19,21 +19,52 @@ package de.steamwar.fightsystem.utils; +import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.fightsystem.Config; 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 TechHider9 implements BiFunction { +public class TechHider9 extends TechHider8 { - private final Set hiddenBlockIds = BlockIdWrapper.impl.getHiddenBlockIds(); - private final int obfuscateWith = BlockIdWrapper.impl.getObfuscateWith(); + private static final UnaryOperator mapChunkCloner = ProtocolAPI.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); + + protected final Set hiddenBlockIds = BlockIdWrapper.impl.getHiddenBlockIds(); + protected final int obfuscateWith = BlockIdWrapper.impl.getObfuscateWith(); @Override - public byte[] apply(byte[] data, Integer primaryBitMask) { + public Object mapChunkHider(Player p, Object packet) { + if(TechHider.bypass(p, mapChunkX.get(packet), mapChunkZ.get(packet))) + 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) { ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100); int i = 0; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java index a8e4236..6193522 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java @@ -27,6 +27,7 @@ import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.record.GlobalRecorder; +import de.steamwar.fightsystem.utils.ProtocolAPI; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Sound; @@ -131,7 +132,6 @@ public class Fight { } private static final Class playerInfoPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo"); - private static final Reflection.ConstructorInvoker playerInfoConstructor = Reflection.getConstructor(playerInfoPacket); private static final Class playerInfoActionClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$EnumPlayerInfoAction"); public static final Object addPlayer = playerInfoActionClass.getEnumConstants()[0]; private static final Reflection.FieldAccessor playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0); @@ -150,7 +150,7 @@ public class Fight { } public static Object playerInfoPacket(Object action, GameProfile profile, Object mode) { - Object packet = playerInfoConstructor.invoke(); + Object packet = ProtocolAPI.construct(playerInfoPacket); playerInfoAction.set(packet, action); playerInfoData.set(packet, Collections.singletonList(playerInfoDataConstructor.invoke(packet, profile, 0, mode, null))); return packet; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/REntity.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/REntity.java index 3c703d8..cf29185 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/REntity.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/REntity.java @@ -26,10 +26,7 @@ import de.steamwar.core.Core; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.listener.FightScoreboard; -import de.steamwar.fightsystem.utils.BlockIdWrapper; -import de.steamwar.fightsystem.utils.BountifulWrapper; -import de.steamwar.fightsystem.utils.FlatteningWrapper; -import de.steamwar.fightsystem.utils.ProtocolAPI; +import de.steamwar.fightsystem.utils.*; import de.steamwar.sql.SteamwarUser; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; @@ -177,24 +174,22 @@ public class REntity { } private static final Class animationPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutAnimation"); - private static final Reflection.ConstructorInvoker animationConstructor = Reflection.getConstructor(animationPacket); private static final Reflection.FieldAccessor animationEntity = Reflection.getField(animationPacket, int.class, 0); private static final Reflection.FieldAccessor animationAnimation = Reflection.getField(animationPacket, int.class, 1); public void animation(byte animation) { - Object packet = animationConstructor.invoke(); + Object packet = ProtocolAPI.construct(animationPacket); animationEntity.set(packet, entityId); animationAnimation.set(packet, (int) animation); ProtocolAPI.broadcastPacket(packet); } private static final Class velocityPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityVelocity"); - private static final Reflection.ConstructorInvoker velocityConstructor = Reflection.getConstructor(velocityPacket); private static final Reflection.FieldAccessor velocityEntity = Reflection.getField(velocityPacket, int.class, 0); private static final Reflection.FieldAccessor velocityX = Reflection.getField(velocityPacket, int.class, 1); private static final Reflection.FieldAccessor velocityY = Reflection.getField(velocityPacket, int.class, 2); private static final Reflection.FieldAccessor velocityZ = Reflection.getField(velocityPacket, int.class, 3); public void setVelocity(double dX, double dY, double dZ) { - Object packet = velocityConstructor.invoke(); + Object packet = ProtocolAPI.construct(velocityPacket); velocityEntity.set(packet, entityId); velocityX.set(packet, calcVelocity(dX)); velocityY.set(packet, calcVelocity(dY)); @@ -203,11 +198,10 @@ public class REntity { } private static final Class statusPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityStatus"); - private static final Reflection.ConstructorInvoker statusConstructor = Reflection.getConstructor(statusPacket); private static final Reflection.FieldAccessor statusEntity = Reflection.getField(statusPacket, int.class, 0); private static final Reflection.FieldAccessor statusStatus = Reflection.getField(statusPacket, byte.class, 0); public void damage() { - Object packet = statusConstructor.invoke(); + Object packet = ProtocolAPI.construct(statusPacket); statusEntity.set(packet, entityId); statusStatus.set(packet, (byte) 2); ProtocolAPI.broadcastPacket(packet); @@ -251,7 +245,6 @@ public class REntity { } private static final Class destroyPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityDestroy"); - private static final Reflection.ConstructorInvoker destroyConstructor = Reflection.getConstructor(destroyPacket); private static final Reflection.FieldAccessor destroyEntities; static { if(Core.getVersion() > 15) @@ -266,7 +259,7 @@ public class REntity { team.removeEntry(name); } - Object packet = destroyConstructor.invoke(); + Object packet = ProtocolAPI.construct(destroyPacket); destroyEntities.set(packet, Core.getVersion() > 15 ? new IntArrayList(new int[]{entityId}) : new int[]{entityId}); ProtocolAPI.broadcastPacket(packet); } @@ -276,23 +269,21 @@ public class REntity { } private static final Class metadataPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityMetadata"); - private static final Reflection.ConstructorInvoker metadataConstructor = Reflection.getConstructor(metadataPacket); private static final Reflection.FieldAccessor metadataEntity = Reflection.getField(metadataPacket, int.class, 0); private static final Reflection.FieldAccessor metadataMetadata = Reflection.getField(metadataPacket, List.class, 0); private Object getDataWatcherPacket(Object dataWatcherObject, Object value) { - Object packet = metadataConstructor.invoke(); + Object packet = ProtocolAPI.construct(metadataPacket); metadataEntity.set(packet, entityId); metadataMetadata.set(packet, Collections.singletonList(BountifulWrapper.impl.getDataWatcherItem(dataWatcherObject, value))); return packet; } public static final Class teleportPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityTeleport"); - private static final Reflection.ConstructorInvoker teleportConstructor = Reflection.getConstructor(teleportPacket); private static final Reflection.FieldAccessor teleportEntity = Reflection.getField(teleportPacket, int.class, 0); private static final Reflection.FieldAccessor teleportYaw = Reflection.getField(teleportPacket, byte.class, 0); private static final Reflection.FieldAccessor teleportPitch = Reflection.getField(teleportPacket, byte.class, 1); private Object getTeleportPacket(){ - Object packet = teleportConstructor.invoke(); + Object packet = ProtocolAPI.construct(teleportPacket); teleportEntity.set(packet, entityId); BountifulWrapper.impl.setTeleportPacketPosition(packet, locX, locY, locZ); teleportYaw.set(packet, yaw); @@ -301,39 +292,35 @@ public class REntity { } private static final Class headRotationPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityHeadRotation"); - private static final Reflection.ConstructorInvoker headRotationConstructor = Reflection.getConstructor(headRotationPacket); private static final Reflection.FieldAccessor headRotationEntity = Reflection.getField(headRotationPacket, int.class, 0); private static final Reflection.FieldAccessor headRotationYaw = Reflection.getField(headRotationPacket, byte.class, 0); private Object getHeadRotationPacket(){ - Object packet = headRotationConstructor.invoke(); + Object packet = ProtocolAPI.construct(headRotationPacket); headRotationEntity.set(packet, entityId); headRotationYaw.set(packet, headYaw); return packet; } public static final Class spawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutSpawnEntity"); - private static final Reflection.ConstructorInvoker spawnConstructor = Reflection.getConstructor(spawnPacket); private static final Reflection.FieldAccessor spawnEntity = Reflection.getField(spawnPacket, int.class, 0); private Object getSpawnEntityPacket(){ - Object packet = spawnConstructor.invoke(); + Object packet = ProtocolAPI.construct(spawnPacket); spawnEntity.set(packet, entityId); BountifulWrapper.impl.setSpawnPacketUUID(packet, uuid); - FlatteningWrapper.impl.setSpawnPacketType(packet, entityType); + ProtocolWrapper.impl.setSpawnPacketType(packet, entityType); return packet; } public static final Class equipmentPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityEquipment"); - private static final Reflection.ConstructorInvoker equipmentConstructor = Reflection.getConstructor(equipmentPacket); private static final Reflection.FieldAccessor equipmentEntity = Reflection.getField(equipmentPacket, int.class, 0); - private static final Class itemStack = Reflection.getClass("{nms}.ItemStack"); - private static final Reflection.FieldAccessor equipmentStack = Reflection.getField(equipmentPacket, itemStack, 0); //TODO: Changed in 1.18 + + public static final Class itemStack = Reflection.getClass("{nms}.ItemStack"); private static final Class craftItemStack = Reflection.getClass("{obc}.inventory.CraftItemStack"); - private static final Reflection.MethodInvoker asNMSCopy = Reflection.getTypedMethod(craftItemStack, "asNMSCopy", itemStack, ItemStack.class); + private static final Reflection.MethodInvoker asNMSCopy = Reflection.getTypedMethod(REntity.craftItemStack, "asNMSCopy", REntity.itemStack, ItemStack.class); private Object getEquipmentPacket(String slot, ItemStack stack){ - Object packet = equipmentConstructor.invoke(); + Object packet = ProtocolAPI.construct(equipmentPacket); equipmentEntity.set(packet, entityId); - BountifulWrapper.impl.setEquipmentPacketSlot(packet, slot); - equipmentStack.set(packet, asNMSCopy.invoke(null, stack)); + ProtocolWrapper.impl.setEquipmentPacketStack(packet, slot, asNMSCopy.invoke(null, stack)); return packet; } @@ -342,11 +329,10 @@ public class REntity { } public static final Class namedSpawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutNamedEntitySpawn"); - private static final Reflection.ConstructorInvoker namedSpawnConstructor = Reflection.getConstructor(namedSpawnPacket); private static final Reflection.FieldAccessor namedSpawnEntity = Reflection.getField(namedSpawnPacket, int.class, 0); private static final Reflection.FieldAccessor namedSpawnUUID = Reflection.getField(namedSpawnPacket, UUID.class, 0); private Object getNamedSpawnPacket(){ - Object packet = namedSpawnConstructor.invoke(); + Object packet = ProtocolAPI.construct(namedSpawnPacket); namedSpawnEntity.set(packet, entityId); namedSpawnUUID.set(packet, uuid); FlatteningWrapper.impl.setNamedSpawnPacketDataWatcher(packet); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java index 18a2706..ffc6217 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java @@ -54,7 +54,6 @@ public class BountifulWrapper { Object getDataWatcherItem(Object dataWatcherObject, Object value); void setTeleportPacketPosition(Object packet, double x, double y, double z); void setSpawnPacketUUID(Object packet, UUID uuid); - void setEquipmentPacketSlot(Object packet, String slot); void sendBar(Player player, FightTeam team, double progress, String text); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FlatteningWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FlatteningWrapper.java index 13a5ab1..34c4c4f 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FlatteningWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FlatteningWrapper.java @@ -24,7 +24,6 @@ import de.steamwar.fightsystem.FightSystem; import org.bukkit.DyeColor; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.entity.EntityType; import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -52,6 +51,5 @@ public class FlatteningWrapper { boolean checkPistonMoving(Block block); void setNamedSpawnPacketDataWatcher(Object packet); - void setSpawnPacketType(Object packet, EntityType type); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/ProtocolAPI.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/ProtocolAPI.java index 28ad17a..31a6788 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/ProtocolAPI.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/ProtocolAPI.java @@ -20,6 +20,7 @@ package de.steamwar.fightsystem.utils; import com.comphenix.tinyprotocol.TinyProtocol; +import jdk.internal.misc.Unsafe; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -87,16 +88,19 @@ public class ProtocolAPI { }; } + public static T construct(Class clazz) { + try { + return (T) Unsafe.getUnsafe().allocateInstance(clazz); + } catch (InstantiationException e) { + throw new IllegalStateException(e); + } + } + public static UnaryOperator shallowCloneGenerator(Class clazz) { BiConsumer filler = shallowFill(clazz); return source -> { - Object clone; - try { - clone = clazz.newInstance(); - } catch (InstantiationException | IllegalAccessException e) { - throw new IllegalStateException("Could not clone " + clazz.getName(), e); - } + Object clone = construct(clazz); filler.accept(source, clone); return clone; }; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/ProtocolWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/ProtocolWrapper.java new file mode 100644 index 0000000..05081de --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/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.fightsystem.utils; + +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()); + + void setEquipmentPacketStack(Object packet, String slot, Object stack); + + void setSpawnPacketType(Object packet, EntityType type); + + Object multiBlockChangeHider(Player p, Object packet); + + boolean unfilteredTileEntityDataAction(Object packet); + + BiFunction blockBreakHiderGenerator(Class blockBreakPacket); +} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java index 2e4d601..a645b15 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java @@ -39,16 +39,15 @@ 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 extends StateDependent { - private static final Class blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); + public static final Class blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); private static final Class baseBlockPosition = Reflection.getClass("{nms.core}.BaseBlockPosition"); - private static final Reflection.FieldAccessor blockPositionX = Reflection.getField(baseBlockPosition, int.class, 0); - private static final Reflection.FieldAccessor blockPositionZ = Reflection.getField(baseBlockPosition, int.class, 2); + public static final Reflection.FieldAccessor blockPositionX = Reflection.getField(baseBlockPosition, int.class, 0); + public static final Reflection.FieldAccessor blockPositionZ = Reflection.getField(baseBlockPosition, int.class, 2); - private static final Class iBlockData = Reflection.getClass("{nms.world.level.block.state}.IBlockData"); + public static final Class iBlockData = Reflection.getClass("{nms.world.level.block.state}.IBlockData"); private static final Class block = Reflection.getClass("{nms.world.level.block}.Block"); private static final Reflection.MethodInvoker getBlockByBlockData = Reflection.getTypedMethod(iBlockData, null, block); private static final Reflection.MethodInvoker getBlockDataByBlock = Reflection.getTypedMethod(block, null, iBlockData); @@ -59,25 +58,28 @@ public class TechHider extends StateDependent { public static final boolean ENABLED = !Config.OnlyPublicSchematics && !Config.test() && Config.TechhiderActive; - private final Object obfuscateIBlockData = getBlockDataByBlock.invoke(getBlockByMaterial.invoke(null, Material.getMaterial(Config.ObfuscateWith.toUpperCase()))); + public static final Object obfuscateIBlockData = getBlockDataByBlock.invoke(getBlockByMaterial.invoke(null, Material.getMaterial(Config.ObfuscateWith.toUpperCase()))); private final Map, BiFunction> techhiders = new HashMap<>(); - private final BiFunction chunkDataHider; + + public interface ChunkHider { + Class mapChunkPacket(); + Object mapChunkHider(Player p, Object packet); + } public TechHider(){ super(ENABLED, FightState.Schem); - chunkDataHider = VersionDependent.getVersionImpl(FightSystem.getPlugin()); - techhiders.put(blockActionPacket, this::blockActionHider); techhiders.put(blockChangePacket, this::blockChangeHider); techhiders.put(tileEntityDataPacket, this::tileEntityDataHider); - techhiders.put(multiBlockChangePacket, this::multiBlockChangeHider); - if(Core.getVersion() > 8) { - techhiders.put(mapChunkPacket, this::mapChunkHider); - } + techhiders.put(multiBlockChangePacket, ProtocolWrapper.impl::multiBlockChangeHider); + + ChunkHider chunkHider = VersionDependent.getVersionImpl(FightSystem.getPlugin()); + techhiders.put(chunkHider.mapChunkPacket(), chunkHider::mapChunkHider); + if(Core.getVersion() > 12) { Class blockBreakClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutBlockBreak"); - techhiders.put(blockBreakClass, blockBreakHiderGenerator(blockBreakClass)); + techhiders.put(blockBreakClass, ProtocolWrapper.impl.blockBreakHiderGenerator(blockBreakClass)); } if(Core.getVersion() > 8){ @@ -98,72 +100,10 @@ public class TechHider extends StateDependent { techhiders.keySet().forEach(ProtocolAPI::removeOutgoingHandler); } - private static final Class nbtTagCompound = Reflection.getClass("{nms.nbt}.NBTTagCompound"); - private static final Reflection.MethodInvoker nbtTagGetString = Reflection.getTypedMethod(nbtTagCompound, null, String.class, String.class); + public static final Class multiBlockChangePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutMultiBlockChange"); + public static final UnaryOperator multiBlockChangeCloner = ProtocolAPI.shallowCloneGenerator(TechHider.multiBlockChangePacket); - //TODO - private static final Class mapChunkPacket = Reflection.getClass("{nms}.PacketPlayOutMapChunk"); - private static final UnaryOperator mapChunkCloner = ProtocolAPI.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; - private static final Reflection.FieldAccessor mapChunkBlockEntities; - private static final Reflection.FieldAccessor mapChunkData; - static { - if(Core.getVersion() > 8) { - mapChunkBitMask = Reflection.getField(mapChunkPacket, int.class, 2); - mapChunkBlockEntities = Reflection.getField(mapChunkPacket, List.class, 0); - mapChunkData = Reflection.getField(mapChunkPacket, byte[].class, 0); - }else { - mapChunkBitMask = null; - mapChunkBlockEntities = null; - mapChunkData = null; - } - } - private Object mapChunkHider(Player p, Object packet) { - if(bypass(p, mapChunkX.get(packet), mapChunkZ.get(packet))) - 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 = chunkDataHider.apply(mapChunkData.get(packet), mapChunkBitMask.get(packet)); - mapChunkData.set(packet, data); - - return packet; - } - - private static final Class multiBlockChangePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutMultiBlockChange"); - //TODO - private static final UnaryOperator multiBlockChangeCloner = ProtocolAPI.shallowCloneGenerator(multiBlockChangePacket); - private static final Class chunkCoordinateIntPair = Reflection.getClass("{nms}.ChunkCoordIntPair"); - private static final Reflection.FieldAccessor multiBlockChangeChunk = Reflection.getField(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, multiBlockChangePacket, short.class, iBlockData); - private static final BiFunction, Object> multiBlockChangeInfoArrayCloner = ProtocolAPI.arrayCloneGenerator(multiBlockChangeInfo); - private static final Reflection.FieldAccessor multiBlockChangeInfoBlock = Reflection.getField(multiBlockChangeInfo, 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(multiBlockChangePacket, multiBlockChangeInfoArray, 0); - private Object multiBlockChangeHider(Player p, Object packet) { - Object chunkCoords = multiBlockChangeChunk.get(packet); - if(bypass(p, chunkCoordinateX.get(chunkCoords), chunkCoordinateZ.get(chunkCoords))) - return packet; - - Object modpacket = multiBlockChangeCloner.apply(packet); - multiBlockChangeInfos.set(modpacket, multiBlockChangeInfoArrayCloner.apply(multiBlockChangeInfos.get(modpacket), mbci -> { - if(Config.HiddenBlocks.contains(getMaterialByIBlockData(multiBlockChangeInfoBlock.get(mbci)).name().toLowerCase())) - return multiBlockChangeInfoConstructor.invoke(modpacket, multiBlockChangeInfoPos.get(mbci), obfuscateIBlockData); - return mbci; - })); - return modpacket; - } - - private static final Class blockChangePacket = Reflection.getClass("{nms}.PacketPlayOutBlockChange"); + 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); @@ -179,7 +119,7 @@ public class TechHider extends StateDependent { return packet; } - private static final Class blockActionPacket = Reflection.getClass("{nms}.PacketPlayOutBlockAction"); + 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); @@ -188,33 +128,14 @@ public class TechHider extends StateDependent { return null; } - private BiFunction blockBreakHiderGenerator(Class blockBreakPacket){ - UnaryOperator blockBreakCloner = ProtocolAPI.shallowCloneGenerator(blockBreakPacket); - Reflection.FieldAccessor blockBreakPosition = Reflection.getField(blockBreakPacket, blockPosition, 0); - Reflection.FieldAccessor blockBreakBlockData = Reflection.getField(blockBreakPacket, iBlockData, 0); - - return (p, packet) -> { - Object pos = blockBreakPosition.get(packet); - if(bypass(p, posToChunk(blockPositionX.get(pos)), posToChunk(blockPositionZ.get(pos)))) - return packet; - - if(Config.HiddenBlocks.contains(getMaterialByIBlockData(blockBreakBlockData.get(packet)).name().toLowerCase())){ - packet = blockBreakCloner.apply(packet); - blockBreakBlockData.set(packet, obfuscateIBlockData); - } - return packet; - }; - } - - private static final Class tileEntityDataPacket = Reflection.getClass("{nms}.PacketPlayOutTileEntityData"); + public static final Class tileEntityDataPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutTileEntityData"); private static final Reflection.FieldAccessor tileEntityDataPosition = Reflection.getField(tileEntityDataPacket, blockPosition, 0); - private static final Reflection.FieldAccessor tileEntityDataAction = Reflection.getField(tileEntityDataPacket, int.class, 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(tileEntityDataAction.get(packet) != 9) + if(ProtocolWrapper.impl.unfilteredTileEntityDataAction(packet)) return packet; return null; } @@ -241,7 +162,7 @@ public class TechHider extends StateDependent { }, 40); } - static boolean bypass(Player p, int chunkX, int chunkZ){ + public static boolean bypass(Player p, int chunkX, int chunkZ){ if(p == FightSystem.getEventLeiter()) return true; @@ -255,11 +176,11 @@ public class TechHider extends StateDependent { } } - private static Material getMaterialByIBlockData(Object iBlockData) { + public static Material getMaterialByIBlockData(Object iBlockData) { return (Material) getMaterialByBlock.invoke(null, getBlockByBlockData.invoke(iBlockData)); } - private static int posToChunk(int c){ + public static int posToChunk(int c){ int chunk = c / 16; if(c<0) chunk--; From 0924b5acc1d6237abdb4142eabc3be4e3ade8c59 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 5 Feb 2022 12:34:22 +0100 Subject: [PATCH 5/5] 1.18 tested implementation Signed-off-by: Lixfel --- .../fightsystem/utils/ProtocolWrapper12.java | 3 +- FightSystem_18/pom.xml | 6 ++++ .../fightsystem/utils/ProtocolWrapper18.java | 29 ++++++++++++++----- .../fightsystem/utils/TechHider18.java | 21 +++++++++----- .../fightsystem/utils/ProtocolWrapper8.java | 18 +++++++++++- .../de/steamwar/fightsystem/fight/Fight.java | 16 +++++----- .../steamwar/fightsystem/record/REntity.java | 2 +- .../fightsystem/utils/ProtocolWrapper.java | 5 ++++ .../steamwar/fightsystem/utils/TechHider.java | 12 ++------ 9 files changed, 76 insertions(+), 36 deletions(-) diff --git a/FightSystem_12/src/de/steamwar/fightsystem/utils/ProtocolWrapper12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/ProtocolWrapper12.java index 3c376b4..650fb41 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/utils/ProtocolWrapper12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/ProtocolWrapper12.java @@ -20,7 +20,6 @@ package de.steamwar.fightsystem.utils; import com.comphenix.tinyprotocol.Reflection; -import de.steamwar.fightsystem.Config; import org.bukkit.entity.Player; import java.util.function.BiFunction; @@ -39,7 +38,7 @@ public class ProtocolWrapper12 extends ProtocolWrapper8 { if(TechHider.bypass(p, TechHider.posToChunk(TechHider.blockPositionX.get(pos)), TechHider.posToChunk(TechHider.blockPositionZ.get(pos)))) return packet; - if(Config.HiddenBlocks.contains(TechHider.getMaterialByIBlockData(blockBreakBlockData.get(packet)).name().toLowerCase())){ + if(ProtocolWrapper.impl.iBlockDataHidden(blockBreakBlockData.get(packet))){ packet = blockBreakCloner.apply(packet); blockBreakBlockData.set(packet, TechHider.obfuscateIBlockData); } diff --git a/FightSystem_18/pom.xml b/FightSystem_18/pom.xml index 4dec64d..c3c4daa 100644 --- a/FightSystem_18/pom.xml +++ b/FightSystem_18/pom.xml @@ -55,6 +55,12 @@ 4.1.68.Final provided + + com.mojang + authlib + 1.5.25 + provided + steamwar Spigot diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/ProtocolWrapper18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/ProtocolWrapper18.java index a47d824..54ee416 100644 --- a/FightSystem_18/src/de/steamwar/fightsystem/utils/ProtocolWrapper18.java +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/ProtocolWrapper18.java @@ -20,9 +20,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; @@ -79,10 +83,8 @@ public class ProtocolWrapper18 implements ProtocolWrapper { } } - private static final Class sectionPosition = Reflection.getClass("{nms.core}.SectionPosition"); - private static final Reflection.FieldAccessor multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, sectionPosition, 0); - private static final Class iBlockDataArray = Reflection.getClass("[L{nms.world.level.block.state}.IBlockData;"); - private static final Reflection.FieldAccessor multiBlockChangeBlocks = Reflection.getField(TechHider.multiBlockChangePacket, iBlockDataArray, 0); + 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) { @@ -90,9 +92,9 @@ public class ProtocolWrapper18 implements ProtocolWrapper { if(TechHider.bypass(p, TechHider.blockPositionX.get(chunkCoords), TechHider.blockPositionZ.get(chunkCoords))) return packet; - Object modpacket = TechHider.multiBlockChangeCloner.apply(packet); - multiBlockChangeBlocks.set(modpacket, iBlockDataArrayCloner.apply(multiBlockChangeBlocks.get(modpacket), block -> Config.HiddenBlocks.contains(TechHider.getMaterialByIBlockData(block).name().toLowerCase()) ? TechHider.obfuscateIBlockData : block)); - return modpacket; + 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); @@ -108,10 +110,21 @@ public class ProtocolWrapper18 implements ProtocolWrapper { if(TechHider.bypass(p, TechHider.posToChunk(TechHider.blockPositionX.get(breakPacket.b())), TechHider.posToChunk(TechHider.blockPositionZ.get(breakPacket.b())))) return packet; - if(!Config.HiddenBlocks.contains(TechHider.getMaterialByIBlockData(breakPacket.c()).name().toLowerCase())) + 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.X.b(((IBlockData) iBlockData).b()).a()); + } } diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/TechHider18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/TechHider18.java index 33362a1..b5fc924 100644 --- a/FightSystem_18/src/de/steamwar/fightsystem/utils/TechHider18.java +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/TechHider18.java @@ -23,9 +23,10 @@ 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; import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; -import net.minecraft.world.entity.EntityTypes; +import net.minecraft.world.level.block.entity.TileEntityTypes; import org.bukkit.World; import org.bukkit.entity.Player; @@ -54,7 +55,7 @@ public class TechHider18 implements TechHider.ChunkHider { 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"); - private static final Reflection.FieldAccessor entityType = Reflection.getField(tileEntity, EntityTypes.class, 0); + private 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(); @@ -67,13 +68,12 @@ public class TechHider18 implements TechHider.ChunkHider { packet = chunkPacketCloner.apply(packet); Object data = chunkDataCloner.apply(chunkData.get(packet)); - tileEntities.set(packet, ((List)tileEntities.get(packet)).stream().filter( - tile -> Config.HiddenBlockEntities.contains(entityType.get(tile).i()) //TODO: i()? + tileEntities.set(data, ((List)tileEntities.get(data)).stream().filter( + tile -> Config.HiddenBlockEntities.contains(IRegistry.ad.b(entityType.get(tile)).a()) ).collect(Collectors.toList())); World world = p.getWorld(); int sections = (world.getMaxHeight() - world.getMinHeight()) / 16; - System.out.println(sections); //TODO dataField.set(data, dataHider(dataField.get(data), sections)); chunkData.set(packet, data); @@ -85,6 +85,9 @@ public class TechHider18 implements TechHider.ChunkHider { int i = 0; while(sections-- > 0) { + buffer.writeBytes(data, i, 2); // Block count + i += 2; + i = containerWalker(data, buffer, i, 15, blockId -> hiddenBlockIds.contains(blockId) ? obfuscateWith : blockId, (curI, dataArrayLength, bitsPerBlock) -> { if(bitsPerBlock < 15) { buffer.writeBytes(data, curI, dataArrayLength * 8); @@ -115,13 +118,17 @@ public class TechHider18 implements TechHider.ChunkHider { byte bitsPerBlock = data[i++]; buffer.writeByte(bitsPerBlock); - if(bitsPerBlock < globalPalette) { + if(bitsPerBlock == 0) { + int paletteValue = TechHider.readVarInt(data, i); + i += TechHider.readVarIntLength(data, i); + buffer.writeBytes(TechHider.writeVarInt(palette.apply(paletteValue))); + }else if(bitsPerBlock < globalPalette) { int paletteLength = TechHider.readVarInt(data, i); int paletteLengthLength = TechHider.readVarIntLength(data, i); buffer.writeBytes(data, i, paletteLengthLength); i += paletteLengthLength; - for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){ + 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))); diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/ProtocolWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/ProtocolWrapper8.java index 91d9646..80c1135 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/ProtocolWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/ProtocolWrapper8.java @@ -20,9 +20,12 @@ 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; @@ -122,7 +125,7 @@ public class ProtocolWrapper8 implements ProtocolWrapper { Object modpacket = TechHider.multiBlockChangeCloner.apply(packet); multiBlockChangeInfos.set(modpacket, multiBlockChangeInfoArrayCloner.apply(multiBlockChangeInfos.get(modpacket), mbci -> { - if(Config.HiddenBlocks.contains(TechHider.getMaterialByIBlockData(multiBlockChangeInfoBlock.get(mbci)).name().toLowerCase())) + if(ProtocolWrapper.impl.iBlockDataHidden(multiBlockChangeInfoBlock.get(mbci))) return multiBlockChangeInfoConstructor.invoke(modpacket, multiBlockChangeInfoPos.get(mbci), TechHider.obfuscateIBlockData); return mbci; })); @@ -139,4 +142,17 @@ public class ProtocolWrapper8 implements ProtocolWrapper { 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_Core/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java index 6193522..80e3cfa 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java @@ -28,6 +28,7 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.fightsystem.utils.ProtocolAPI; +import de.steamwar.fightsystem.utils.ProtocolWrapper; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Sound; @@ -131,20 +132,19 @@ public class Fight { } } - private static final Class playerInfoPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo"); + public static final Class playerInfoPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo"); private static final Class playerInfoActionClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$EnumPlayerInfoAction"); public static final Object addPlayer = playerInfoActionClass.getEnumConstants()[0]; private static final Reflection.FieldAccessor playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0); private static final Object updateGamemode = playerInfoActionClass.getEnumConstants()[1]; public static final Object removePlayer = playerInfoActionClass.getEnumConstants()[4]; private static final Reflection.FieldAccessor playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0); - private static final Class playerInfoDataClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$PlayerInfoData"); - private static final Class enumGamemode = Reflection.getClass(Core.getVersion() > 9 ? "{nms.world.level}.EnumGamemode" : "{nms}.WorldSettings$EnumGamemode"); - public static final Object creative = enumGamemode.getEnumConstants()[2]; - private static final Object spectator = enumGamemode.getEnumConstants()[4]; - private static final Class iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent"); + public static final Class playerInfoDataClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$PlayerInfoData"); + public static final Class enumGamemode = Reflection.getClass(Core.getVersion() > 9 ? "{nms.world.level}.EnumGamemode" : "{nms}.WorldSettings$EnumGamemode"); + public static final Object creative = enumGamemode.getEnumConstants()[Core.getVersion() > 15 ? 1 : 2]; + private static final Object spectator = enumGamemode.getEnumConstants()[Core.getVersion() > 15 ? 3 : 4]; + public static final Class iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent"); - private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClass, playerInfoPacket, GameProfile.class, int.class, enumGamemode, iChatBaseComponent); public static void pseudoSpectator(Player player, boolean enable) { TinyProtocol.instance.sendPacket(player, playerInfoPacket(updateGamemode, new GameProfile(player.getUniqueId(), player.getName()), enable ? creative : spectator)); } @@ -152,7 +152,7 @@ public class Fight { public static Object playerInfoPacket(Object action, GameProfile profile, Object mode) { Object packet = ProtocolAPI.construct(playerInfoPacket); playerInfoAction.set(packet, action); - playerInfoData.set(packet, Collections.singletonList(playerInfoDataConstructor.invoke(packet, profile, 0, mode, null))); + playerInfoData.set(packet, Collections.singletonList(ProtocolWrapper.impl.playerInfoDataConstructor(packet, profile, mode))); return packet; } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/REntity.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/REntity.java index cf29185..3da799d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/REntity.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/REntity.java @@ -314,7 +314,7 @@ public class REntity { public static final Class equipmentPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityEquipment"); private static final Reflection.FieldAccessor equipmentEntity = Reflection.getField(equipmentPacket, int.class, 0); - public static final Class itemStack = Reflection.getClass("{nms}.ItemStack"); + public static final Class itemStack = Reflection.getClass("{nms.world.item}.ItemStack"); private static final Class craftItemStack = Reflection.getClass("{obc}.inventory.CraftItemStack"); private static final Reflection.MethodInvoker asNMSCopy = Reflection.getTypedMethod(REntity.craftItemStack, "asNMSCopy", REntity.itemStack, ItemStack.class); private Object getEquipmentPacket(String slot, ItemStack stack){ diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/ProtocolWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/ProtocolWrapper.java index 05081de..1ca485a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/ProtocolWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/ProtocolWrapper.java @@ -19,6 +19,7 @@ package de.steamwar.fightsystem.utils; +import com.mojang.authlib.GameProfile; import de.steamwar.core.VersionDependent; import de.steamwar.fightsystem.FightSystem; import org.bukkit.entity.EntityType; @@ -38,4 +39,8 @@ public interface ProtocolWrapper { 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 index a645b15..933dae9 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java @@ -48,12 +48,10 @@ public class TechHider extends StateDependent { 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"); - private static final Class block = Reflection.getClass("{nms.world.level.block}.Block"); - private static final Reflection.MethodInvoker getBlockByBlockData = Reflection.getTypedMethod(iBlockData, null, block); + public static final Class block = Reflection.getClass("{nms.world.level.block}.Block"); private static final Reflection.MethodInvoker getBlockDataByBlock = Reflection.getTypedMethod(block, null, iBlockData); - private static final Class craftMagicNumbers = Reflection.getClass("{obc}.util.CraftMagicNumbers"); - private static final Reflection.MethodInvoker getMaterialByBlock = Reflection.getTypedMethod(craftMagicNumbers, "getMaterial", Material.class, block); + 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; @@ -112,7 +110,7 @@ public class TechHider extends StateDependent { if(bypass(p, posToChunk(blockPositionX.get(pos)), posToChunk(blockPositionZ.get(pos)))) return packet; - if(Config.HiddenBlocks.contains(getMaterialByIBlockData(blockChangeBlockData.get(packet)).name().toLowerCase())){ + if(ProtocolWrapper.impl.iBlockDataHidden(blockChangeBlockData.get(packet))) { packet = blockChangeCloner.apply(packet); blockChangeBlockData.set(packet, obfuscateIBlockData); } @@ -176,10 +174,6 @@ public class TechHider extends StateDependent { } } - public static Material getMaterialByIBlockData(Object iBlockData) { - return (Material) getMaterialByBlock.invoke(null, getBlockByBlockData.invoke(iBlockData)); - } - public static int posToChunk(int c){ int chunk = c / 16; if(c<0)