From e97d6a48c33191e4326d0214575ee96f5a819749 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 1 Feb 2023 12:51:14 +0100 Subject: [PATCH 01/17] Simplify some multiversioning TODOs: - Test if techhider still applied in sendChunk - Test if 1.15 CraftMagicNumbers loads class --- .../de/steamwar/core/FlatteningWrapper14.java | 23 ++++++++++ .../steamwar/core/CraftbukkitWrapper18.java | 10 +++-- .../de/steamwar/core/ProtocolWrapper18.java | 30 ------------- .../steamwar/core/CraftbukkitWrapper19.java | 42 ------------------- .../de/steamwar/core/ProtocolWrapper19.java | 29 ------------- .../de/steamwar/core/FlatteningWrapper8.java | 27 ++++++++++++ .../de/steamwar/core/ProtocolWrapper8.java | 33 --------------- .../src/de/steamwar/core/Core.java | 24 +---------- .../de/steamwar/core/FlatteningWrapper.java | 6 +++ .../src/de/steamwar/core/ProtocolWrapper.java | 3 -- .../src/de/steamwar/entity/REntity.java | 2 +- .../src/de/steamwar/entity/REntityServer.java | 3 +- 12 files changed, 67 insertions(+), 165 deletions(-) delete mode 100644 SpigotCore_19/src/de/steamwar/core/CraftbukkitWrapper19.java diff --git a/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java b/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java index 84a4dc6..e650a29 100644 --- a/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java +++ b/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java @@ -22,6 +22,8 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.Reflection; import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.SkullMeta; @@ -322,4 +324,25 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper public Object formatDisplayName(String displayName) { return displayName != null ? Optional.of(ChatWrapper.impl.stringToChatComponent(displayName)) : Optional.empty(); } + + private static final Reflection.FieldAccessor spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, Reflection.getClass("{nms.world.entity}.EntityTypes"), 0); + private static final Reflection.FieldAccessor spawnLivingType = Core.getVersion() > 19 ? spawnType : Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1); + private static final Reflection.MethodInvoker getEntityTypes = Reflection.getMethod("{obc}.util.CraftMagicNumbers", "getEntityTypes", EntityType.class); + private static final Map types = new HashMap<>(); + static { + types.put(EntityType.ARMOR_STAND, 1); + } + @Override + public void setSpawnPacketType(Object packet, EntityType type) { + if(type.isAlive()) { + spawnLivingType.set(packet, Core.getVersion() > 18 ? getEntityTypes.invoke(null, type) : types.get(type)); + } else { + spawnType.set(packet, getEntityTypes.invoke(null, type)); + } + } + + @Override + public int getViewDistance(Player player) { + return player.getClientViewDistance(); + } } diff --git a/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java b/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java index 9f7aa13..6296ac2 100644 --- a/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java +++ b/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java @@ -19,19 +19,21 @@ package de.steamwar.core; +import com.comphenix.tinyprotocol.Reflection; +import com.comphenix.tinyprotocol.TinyProtocol; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; import net.minecraft.server.MinecraftServer; import net.minecraft.world.level.chunk.Chunk; -import org.bukkit.craftbukkit.v1_18_R2.CraftChunk; -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; import org.bukkit.entity.Player; public class CraftbukkitWrapper18 implements CraftbukkitWrapper.ICraftbukkitWrapper { + private static final Reflection.MethodInvoker getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle"); + @Override public void sendChunk(Player p, int chunkX, int chunkZ) { - Chunk chunk = ((CraftChunk)p.getWorld().getChunkAt(chunkX, chunkZ)).getHandle(); - ((CraftPlayer)p).getHandle().b.a(new ClientboundLevelChunkWithLightPacket(chunk, chunk.q.l_(), null, null, false)); + Chunk chunk = (Chunk) getHandle.invoke(p.getWorld().getChunkAt(chunkX, chunkZ)); + TinyProtocol.instance.sendPacket(p, new ClientboundLevelChunkWithLightPacket(chunk, chunk.q.l_(), null, null, false)); } @Override diff --git a/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java b/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java index 2a88cb4..94f6131 100644 --- a/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java +++ b/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java @@ -22,8 +22,6 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.Reflection; import com.mojang.authlib.GameProfile; import com.mojang.datafixers.util.Pair; -import net.minecraft.world.entity.EntityTypes; -import org.bukkit.entity.EntityType; import java.util.Collections; import java.util.List; @@ -36,34 +34,6 @@ public class ProtocolWrapper18 implements ProtocolWrapper { equipmentStack.set(packet, Collections.singletonList(new Pair<>(slot, stack))); } - private static final Reflection.FieldAccessor spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, EntityTypes.class, 0); - private static final Reflection.FieldAccessor spawnLivingType = Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1); - @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; - case ITEM_FRAME: - spawnType.set(packet, EntityTypes.R); - break; - case FALLING_BLOCK: - spawnType.set(packet, EntityTypes.C); - break; - case ARMOR_STAND: - spawnLivingType.set(packet, 1); - break; - default: - throw new IllegalArgumentException(type.name() + " is not implemented"); - } - } - private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClass, GameProfile.class, int.class, enumGamemode, iChatBaseComponent); @Override public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) { diff --git a/SpigotCore_19/src/de/steamwar/core/CraftbukkitWrapper19.java b/SpigotCore_19/src/de/steamwar/core/CraftbukkitWrapper19.java deleted file mode 100644 index 99e9479..0000000 --- a/SpigotCore_19/src/de/steamwar/core/CraftbukkitWrapper19.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.core; - -import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; -import net.minecraft.server.MinecraftServer; -import net.minecraft.world.level.chunk.Chunk; -import org.bukkit.craftbukkit.v1_19_R1.CraftChunk; -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class CraftbukkitWrapper19 implements CraftbukkitWrapper.ICraftbukkitWrapper { - - @Override - public void sendChunk(Player p, int chunkX, int chunkZ) { - Chunk chunk = ((CraftChunk)p.getWorld().getChunkAt(chunkX, chunkZ)).getHandle(); - ((CraftPlayer)p).getHandle().b.a(new ClientboundLevelChunkWithLightPacket(chunk, chunk.q.l_(), null, null, false)); - } - - @Override - @SuppressWarnings("deprecation") - public double[] getSpigotTPS() { - return MinecraftServer.getServer().recentTps; - } -} diff --git a/SpigotCore_19/src/de/steamwar/core/ProtocolWrapper19.java b/SpigotCore_19/src/de/steamwar/core/ProtocolWrapper19.java index 66cc47c..86c23fb 100644 --- a/SpigotCore_19/src/de/steamwar/core/ProtocolWrapper19.java +++ b/SpigotCore_19/src/de/steamwar/core/ProtocolWrapper19.java @@ -22,8 +22,6 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.Reflection; import com.mojang.authlib.GameProfile; import com.mojang.datafixers.util.Pair; -import net.minecraft.world.entity.EntityTypes; -import org.bukkit.entity.EntityType; import java.util.Collections; import java.util.List; @@ -36,33 +34,6 @@ public class ProtocolWrapper19 implements ProtocolWrapper { equipmentStack.set(packet, Collections.singletonList(new Pair<>(slot, stack))); } - private static final Reflection.FieldAccessor spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, EntityTypes.class, 0); - @Override - public void setSpawnPacketType(Object packet, EntityType type) { - switch(type) { - case PRIMED_TNT: - spawnType.set(packet, EntityTypes.av); - break; - case ARROW: - spawnType.set(packet, EntityTypes.e); - break; - case FIREBALL: - spawnType.set(packet, EntityTypes.V); - break; - case ITEM_FRAME: - spawnType.set(packet, EntityTypes.U); - break; - case ARMOR_STAND: - spawnType.set(packet, EntityTypes.d); - break; - case FALLING_BLOCK: - spawnType.set(packet, EntityTypes.E); - break; - default: - throw new IllegalArgumentException(type.name() + " is not implemented"); - } - } - private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClass, GameProfile.class, int.class, enumGamemode, iChatBaseComponent, Reflection.getClass("net.minecraft.world.entity.player.ProfilePublicKey$a")); @Override public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) { diff --git a/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java b/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java index 44f5c1a..8df959b 100644 --- a/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java +++ b/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java @@ -21,9 +21,14 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.Reflection; import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.SkullMeta; +import java.util.HashMap; +import java.util.Map; + public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper { private static final Reflection.FieldAccessor scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, String.class, 1); @@ -84,4 +89,26 @@ public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper public Object formatDisplayName(String displayName) { return displayName != null ? displayName : ""; } + + + private static final Reflection.FieldAccessor spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, int.class, Core.getVersion() > 8 ? 6 : 9); + private static final Reflection.FieldAccessor spawnLivingType = Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1); + private static final Map types = new HashMap<>(); + static { + types.put(EntityType.PRIMED_TNT, 50); + types.put(EntityType.ARMOR_STAND, 30); + types.put(EntityType.ARROW, 60); + types.put(EntityType.FIREBALL, 63); + types.put(EntityType.ITEM_FRAME, 18); + types.put(EntityType.FALLING_BLOCK, 21); + } + @Override + public void setSpawnPacketType(Object packet, EntityType type) { + (type.isAlive() ? spawnLivingType : spawnType).set(packet, types.get(type)); + } + + @Override + public int getViewDistance(Player player) { + return 10; + } } diff --git a/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java b/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java index a6a43de..98aa0a2 100644 --- a/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java +++ b/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java @@ -21,10 +21,6 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.Reflection; import com.mojang.authlib.GameProfile; -import org.bukkit.entity.EntityType; - -import java.util.HashMap; -import java.util.Map; public class ProtocolWrapper8 implements ProtocolWrapper { @@ -45,35 +41,6 @@ public class ProtocolWrapper8 implements ProtocolWrapper { equipmentStack.set(packet, stack); } - private static final Reflection.FieldAccessor spawnType; - private static final Reflection.FieldAccessor spawnLivingType = Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1); - private static final Map types = new HashMap<>(); - - static { - if(Core.getVersion() < 14) { - spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, int.class, Core.getVersion() > 8 ? 6 : 9); - types.put(EntityType.PRIMED_TNT, 50); - types.put(EntityType.ARMOR_STAND, 30); - types.put(EntityType.ARROW, 60); - types.put(EntityType.FIREBALL, 63); - types.put(EntityType.ITEM_FRAME, 18); - types.put(EntityType.FALLING_BLOCK, 21); - } else { - Class entityTypes = Reflection.getClass("{nms.world.entity}.EntityTypes"); - spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, entityTypes, 0); - types.put(EntityType.ARMOR_STAND, 1); - for(EntityType type : new EntityType[]{EntityType.PRIMED_TNT, EntityType.ARROW, EntityType.FIREBALL, EntityType.ITEM_FRAME, EntityType.FALLING_BLOCK}) - types.put(type, Reflection.getField(entityTypes, type != EntityType.PRIMED_TNT ? type.name() : "TNT", entityTypes).get(null)); - } - } - @Override - public void setSpawnPacketType(Object packet, EntityType type) { - if(type.isAlive()) - spawnLivingType.set(packet, types.get(type)); - else - spawnType.set(packet, types.get(type)); - } - private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClass, playerInfoPacket, GameProfile.class, int.class, enumGamemode, iChatBaseComponent); @Override public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) { diff --git a/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore_Main/src/de/steamwar/core/Core.java index bc7e957..ff0d555 100644 --- a/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -46,28 +46,8 @@ public class Core extends JavaPlugin{ public static final Message MESSAGE = new Message("SpigotCore", Core.class.getClassLoader()); - private static final int VERSION; - static{ - String packageName = Bukkit.getServer().getClass().getPackage().getName(); - if(packageName.contains("1_19")) - VERSION = 19; - else if(packageName.contains("1_18")) - VERSION = 18; - else if(packageName.contains("1_15")) - VERSION = 15; - else if(packageName.contains("1_14")) - VERSION = 14; - else if(packageName.contains("1_12")) - VERSION = 12; - else if(packageName.contains("1_10")) - VERSION = 10; - else if(packageName.contains("1_9")) - VERSION = 9; - else if(packageName.contains("1_8")) - VERSION = 8; - else - VERSION = 18; - } + private static final int VERSION = Integer.parseInt(Bukkit.getServer().getClass().getPackage().getName().split("_", 3)[1]); + public static int getVersion(){ return VERSION; } diff --git a/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java b/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java index 3f5f205..12423ae 100644 --- a/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java +++ b/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java @@ -21,6 +21,8 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.Reflection; import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; public class FlatteningWrapper { @@ -42,6 +44,10 @@ public class FlatteningWrapper { Object getPose(EntityPose pose); void setNamedSpawnPacketDataWatcher(Object packet); Object formatDisplayName(String displayName); + + void setSpawnPacketType(Object packet, EntityType type); + + int getViewDistance(Player player); } public enum EntityPose { diff --git a/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java b/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java index a1f219b..ca02e58 100644 --- a/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java +++ b/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java @@ -21,7 +21,6 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.Reflection; import com.mojang.authlib.GameProfile; -import org.bukkit.entity.EntityType; public interface ProtocolWrapper { @@ -41,8 +40,6 @@ public interface ProtocolWrapper { void setEquipmentPacketStack(Object packet, Object slot, Object stack); - void setSpawnPacketType(Object packet, EntityType type); - Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode); } diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore_Main/src/de/steamwar/entity/REntity.java index d6ace1a..bc7736e 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -394,7 +394,7 @@ public class REntity { return entity -> { Object packet = packetGenerator.apply(entity); uuid.set(packet, entity.uuid); - ProtocolWrapper.impl.setSpawnPacketType(packet, entity.entityType); + FlatteningWrapper.impl.setSpawnPacketType(packet, entity.entityType); return packet; }; } diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index 70a5fee..1b85252 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -21,6 +21,7 @@ package de.steamwar.entity; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.Core; +import de.steamwar.core.FlatteningWrapper; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -212,7 +213,7 @@ public class REntityServer implements Listener { } private int viewRadius(Player player) { - return player.getClientViewDistance() / 2; + return FlatteningWrapper.impl.getViewDistance(player) / 2; } private long entityToId(REntity entity) { From 6cb89ee93844a667215953ee27b60585c700bad4 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 1 Feb 2023 14:50:28 +0100 Subject: [PATCH 02/17] Generalize BlockIds --- .../src/de/steamwar/techhider/BlockIds14.java | 43 +++++++++++--- .../src/de/steamwar/techhider/BlockIds15.java | 52 ----------------- .../src/de/steamwar/techhider/BlockIds18.java | 57 ------------------- .../src/de/steamwar/techhider/BlockIds19.java | 57 ------------------- 4 files changed, 34 insertions(+), 175 deletions(-) delete mode 100644 SpigotCore_15/src/de/steamwar/techhider/BlockIds15.java delete mode 100644 SpigotCore_18/src/de/steamwar/techhider/BlockIds18.java delete mode 100644 SpigotCore_19/src/de/steamwar/techhider/BlockIds19.java diff --git a/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java b/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java index 1a946ef..f4be936 100644 --- a/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java +++ b/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java @@ -19,34 +19,59 @@ package de.steamwar.techhider; -import net.minecraft.server.v1_14_R1.*; +import com.comphenix.tinyprotocol.Reflection; +import com.google.common.collect.ImmutableList; import org.bukkit.Material; import java.util.HashSet; import java.util.Set; public class BlockIds14 implements BlockIds { + + private static final Class iRegistry = Reflection.getClass("{nms.core}.IRegistry"); + private static final Class minecraftKey = Reflection.getClass("{nms.resources}.MinecraftKey"); + private static final Class blockStateList = Reflection.getClass("{nms.world.level.block.state}.BlockStateList"); + private static final Class fluidTypeFlowing = Reflection.getClass("{nms.world.level.material}.FluidTypeFlowing"); + private static final Class fluid = Reflection.getClass("{nms.world.level.material}.Fluid"); + + private static final Reflection.MethodInvoker getBlockData = Reflection.getTypedMethod(TechHider.block, null, TechHider.iBlockData); @Override public int materialToId(Material material) { - return Block.getCombinedId(IRegistry.BLOCK.get(new MinecraftKey(material.name().toLowerCase())).getBlockData()); + return getCombinedId(getBlockData.invoke(getBlock(material))); } + private static final Reflection.MethodInvoker getStates = Reflection.getTypedMethod(TechHider.block, null, blockStateList); + private static final Reflection.MethodInvoker getStateList = Reflection.getTypedMethod(blockStateList, null, ImmutableList.class); + private static final Object water = Reflection.getTypedMethod(fluidTypeFlowing, null, fluid).invoke(Reflection.getField(Reflection.getClass("{nms.world.level.material}.FluidTypes"), fluidTypeFlowing, 1).get(null)); + private static final Iterable registryBlockId = (Iterable) Reflection.getField(TechHider.block, Reflection.getClass("{nms.core}.RegistryBlockID"), 0).get(null); + private static final Reflection.MethodInvoker getFluid = Reflection.getTypedMethod(TechHider.iBlockData, null, fluid); @Override public Set materialToAllIds(Material material) { Set ids = new HashSet<>(); - for(IBlockData data : IRegistry.BLOCK.get(new MinecraftKey(material.name().toLowerCase())).getStates().a()) { - ids.add(Block.getCombinedId(data)); + for(Object data : (ImmutableList) getStateList.invoke(getStates.invoke(getBlock(material)))) { + ids.add(getCombinedId(data)); } - if(material == Material.WATER){ - Fluid water = FluidTypes.WATER.a(false); - for(IBlockData data : Block.REGISTRY_ID){ - if(data.p() == water){ - ids.add(Block.getCombinedId(data)); + if(material == Material.WATER) { + for(Object data : registryBlockId) { + if(getFluid.invoke(data) == water) { + ids.add(getCombinedId(data)); } } } return ids; } + + private static final Reflection.ConstructorInvoker newMinecraftkey = Reflection.getConstructor(minecraftKey, String.class); + private static final Reflection.MethodInvoker registryBlocksGet = Reflection.getTypedMethod(iRegistry, null, Object.class, minecraftKey); + private static final Object blockRegistry = Reflection.getField(iRegistry, Reflection.getClass("{nms.core}.RegistryBlocks"), 0, TechHider.block).get(null); + private Object getBlock(Material material) { + return registryBlocksGet.invoke(blockRegistry, newMinecraftkey.invoke(material.name().toLowerCase())); + } + + private static final Reflection.MethodInvoker getCombinedId = Reflection.getTypedMethod(TechHider.block, null, int.class, TechHider.iBlockData); + private int getCombinedId(Object blockData) { + return (int) getCombinedId.invoke(null, blockData); + } } diff --git a/SpigotCore_15/src/de/steamwar/techhider/BlockIds15.java b/SpigotCore_15/src/de/steamwar/techhider/BlockIds15.java deleted file mode 100644 index 15e7c4d..0000000 --- a/SpigotCore_15/src/de/steamwar/techhider/BlockIds15.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.techhider; - -import net.minecraft.server.v1_15_R1.*; -import org.bukkit.Material; - -import java.util.HashSet; -import java.util.Set; - -public class BlockIds15 implements BlockIds { - @Override - public int materialToId(Material material) { - return Block.getCombinedId(IRegistry.BLOCK.get(new MinecraftKey(material.name().toLowerCase())).getBlockData()); - } - - @Override - public Set materialToAllIds(Material material) { - Set ids = new HashSet<>(); - for(IBlockData data : IRegistry.BLOCK.get(new MinecraftKey(material.name().toLowerCase())).getStates().a()) { - ids.add(Block.getCombinedId(data)); - } - - if(material == Material.WATER){ - Fluid water = FluidTypes.WATER.a(false); - for(IBlockData data : Block.REGISTRY_ID){ - if(data.getFluid() == water){ - ids.add(Block.getCombinedId(data)); - } - } - } - - return ids; - } -} diff --git a/SpigotCore_18/src/de/steamwar/techhider/BlockIds18.java b/SpigotCore_18/src/de/steamwar/techhider/BlockIds18.java deleted file mode 100644 index 13cf029..0000000 --- a/SpigotCore_18/src/de/steamwar/techhider/BlockIds18.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.techhider; - -import net.minecraft.core.IRegistry; -import net.minecraft.resources.MinecraftKey; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.level.material.Fluid; -import net.minecraft.world.level.material.FluidTypes; -import org.bukkit.Material; - -import java.util.HashSet; -import java.util.Set; - -public class BlockIds18 implements BlockIds { - @Override - public int materialToId(Material material) { - return Block.i(IRegistry.U.a(new MinecraftKey(material.name().toLowerCase())).n()); - } - - @Override - public Set materialToAllIds(Material material) { - Set ids = new HashSet<>(); - for(IBlockData data : IRegistry.U.a(new MinecraftKey(material.name().toLowerCase())).m().a()){ - ids.add(Block.i(data)); - } - - if(material == Material.WATER){ - Fluid water = FluidTypes.c.h(); - for(IBlockData data : Block.o) { - if(data.o() == water) { - ids.add(Block.i(data)); - } - } - } - - return ids; - } -} diff --git a/SpigotCore_19/src/de/steamwar/techhider/BlockIds19.java b/SpigotCore_19/src/de/steamwar/techhider/BlockIds19.java deleted file mode 100644 index e1e0b54..0000000 --- a/SpigotCore_19/src/de/steamwar/techhider/BlockIds19.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.techhider; - -import net.minecraft.core.IRegistry; -import net.minecraft.resources.MinecraftKey; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.level.material.Fluid; -import net.minecraft.world.level.material.FluidTypes; -import org.bukkit.Material; - -import java.util.HashSet; -import java.util.Set; - -public class BlockIds19 implements BlockIds { - @Override - public int materialToId(Material material) { - return Block.i(IRegistry.V.a(new MinecraftKey(material.name().toLowerCase())).m()); - } - - @Override - public Set materialToAllIds(Material material) { - Set ids = new HashSet<>(); - for(IBlockData data : IRegistry.V.a(new MinecraftKey(material.name().toLowerCase())).k().a()){ - ids.add(Block.i(data)); - } - - if(material == Material.WATER){ - Fluid water = FluidTypes.c.h(); - for(IBlockData data : Block.o) { - if(data.p() == water) { - ids.add(Block.i(data)); - } - } - } - - return ids; - } -} From a0f59e1a10ae8b8386ec0485abcc03a81af06e20 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 1 Feb 2023 15:42:08 +0100 Subject: [PATCH 03/17] Reflection getTps, sendChunk, tileEntityVisible --- .../steamwar/core/CraftbukkitWrapper10.java | 40 ------------------- .../steamwar/core/CraftbukkitWrapper12.java | 40 ------------------- .../steamwar/core/CraftbukkitWrapper14.java | 40 ------------------- .../steamwar/core/CraftbukkitWrapper15.java | 40 ------------------- .../steamwar/core/CraftbukkitWrapper18.java | 7 ---- .../de/steamwar/techhider/ChunkHider18.java | 10 +++-- .../de/steamwar/techhider/ChunkHider19.java | 31 -------------- .../de/steamwar/core/CraftbukkitWrapper9.java | 19 ++++----- .../de/steamwar/core/CraftbukkitWrapper.java | 1 - .../src/de/steamwar/core/TPSWatcher.java | 6 ++- 10 files changed, 20 insertions(+), 214 deletions(-) delete mode 100644 SpigotCore_10/src/de/steamwar/core/CraftbukkitWrapper10.java delete mode 100644 SpigotCore_12/src/de/steamwar/core/CraftbukkitWrapper12.java delete mode 100644 SpigotCore_14/src/de/steamwar/core/CraftbukkitWrapper14.java delete mode 100644 SpigotCore_15/src/de/steamwar/core/CraftbukkitWrapper15.java delete mode 100644 SpigotCore_19/src/de/steamwar/techhider/ChunkHider19.java diff --git a/SpigotCore_10/src/de/steamwar/core/CraftbukkitWrapper10.java b/SpigotCore_10/src/de/steamwar/core/CraftbukkitWrapper10.java deleted file mode 100644 index 8916735..0000000 --- a/SpigotCore_10/src/de/steamwar/core/CraftbukkitWrapper10.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.core; - -import net.minecraft.server.v1_10_R1.MinecraftServer; -import net.minecraft.server.v1_10_R1.PacketPlayOutMapChunk; -import org.bukkit.craftbukkit.v1_10_R1.CraftChunk; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class CraftbukkitWrapper10 implements CraftbukkitWrapper.ICraftbukkitWrapper { - - @Override - public void sendChunk(Player p, int chunkX, int chunkZ) { - ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunkX, chunkZ)).getHandle(), 65535)); - } - - @SuppressWarnings("deprecation") - @Override - public double[] getSpigotTPS() { - return MinecraftServer.getServer().recentTps; - } -} diff --git a/SpigotCore_12/src/de/steamwar/core/CraftbukkitWrapper12.java b/SpigotCore_12/src/de/steamwar/core/CraftbukkitWrapper12.java deleted file mode 100644 index 3d084b3..0000000 --- a/SpigotCore_12/src/de/steamwar/core/CraftbukkitWrapper12.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.core; - -import net.minecraft.server.v1_12_R1.MinecraftServer; -import net.minecraft.server.v1_12_R1.PacketPlayOutMapChunk; -import org.bukkit.craftbukkit.v1_12_R1.CraftChunk; -import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class CraftbukkitWrapper12 implements CraftbukkitWrapper.ICraftbukkitWrapper { - - @Override - public void sendChunk(Player p, int chunkX, int chunkZ) { - ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunkX, chunkZ)).getHandle(), 65535)); - } - - @SuppressWarnings("deprecation") - @Override - public double[] getSpigotTPS() { - return MinecraftServer.getServer().recentTps; - } -} diff --git a/SpigotCore_14/src/de/steamwar/core/CraftbukkitWrapper14.java b/SpigotCore_14/src/de/steamwar/core/CraftbukkitWrapper14.java deleted file mode 100644 index bc27af3..0000000 --- a/SpigotCore_14/src/de/steamwar/core/CraftbukkitWrapper14.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.core; - -import net.minecraft.server.v1_14_R1.MinecraftServer; -import net.minecraft.server.v1_14_R1.PacketPlayOutMapChunk; -import org.bukkit.craftbukkit.v1_14_R1.CraftChunk; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class CraftbukkitWrapper14 implements CraftbukkitWrapper.ICraftbukkitWrapper { - - @Override - public void sendChunk(Player p, int chunkX, int chunkZ) { - ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunkX, chunkZ)).getHandle(), 65535)); - } - - @SuppressWarnings("deprecation") - @Override - public double[] getSpigotTPS() { - return MinecraftServer.getServer().recentTps; - } -} diff --git a/SpigotCore_15/src/de/steamwar/core/CraftbukkitWrapper15.java b/SpigotCore_15/src/de/steamwar/core/CraftbukkitWrapper15.java deleted file mode 100644 index d5b908f..0000000 --- a/SpigotCore_15/src/de/steamwar/core/CraftbukkitWrapper15.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.core; - -import net.minecraft.server.v1_15_R1.MinecraftServer; -import net.minecraft.server.v1_15_R1.PacketPlayOutMapChunk; -import org.bukkit.craftbukkit.v1_15_R1.CraftChunk; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class CraftbukkitWrapper15 implements CraftbukkitWrapper.ICraftbukkitWrapper { - - @Override - public void sendChunk(Player p, int chunkX, int chunkZ) { - ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunkX, chunkZ)).getHandle(), 65535)); - } - - @SuppressWarnings("deprecation") - @Override - public double[] getSpigotTPS() { - return MinecraftServer.getServer().recentTps; - } -} diff --git a/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java b/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java index 6296ac2..e3d4ea7 100644 --- a/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java +++ b/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java @@ -22,7 +22,6 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; -import net.minecraft.server.MinecraftServer; import net.minecraft.world.level.chunk.Chunk; import org.bukkit.entity.Player; @@ -35,10 +34,4 @@ public class CraftbukkitWrapper18 implements CraftbukkitWrapper.ICraftbukkitWrap Chunk chunk = (Chunk) getHandle.invoke(p.getWorld().getChunkAt(chunkX, chunkZ)); TinyProtocol.instance.sendPacket(p, new ClientboundLevelChunkWithLightPacket(chunk, chunk.q.l_(), null, null, false)); } - - @Override - @SuppressWarnings("deprecation") - public double[] getSpigotTPS() { - return MinecraftServer.getServer().recentTps; - } } diff --git a/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java b/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java index 53dc78f..e994f63 100644 --- a/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java +++ b/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java @@ -25,6 +25,7 @@ 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.resources.MinecraftKey; import net.minecraft.util.SimpleBitStorage; import net.minecraft.world.level.block.entity.TileEntityTypes; import org.bukkit.World; @@ -53,8 +54,6 @@ public class ChunkHider18 implements 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"); - protected static final Reflection.FieldAccessor entityType = Reflection.getField(tileEntity, TileEntityTypes.class, 0); @Override public BiFunction chunkHiderGenerator(TechHider.BypassEvaluator bypass, int obfuscationTarget, Set obfuscate, Set hiddenBlockEntities) { @@ -76,8 +75,13 @@ public class ChunkHider18 implements ChunkHider { }; } + public static final Class tileEntity = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$a"); + protected static final Reflection.FieldAccessor entityType = Reflection.getField(tileEntity, TileEntityTypes.class, 0); + private static final IRegistry> tileEntityTypes = (IRegistry>) Reflection.getField(IRegistry.class, IRegistry.class, 0, TileEntityTypes.class); + private static final Reflection.MethodInvoker getKey = Reflection.getTypedMethod(IRegistry.class, null, MinecraftKey.class, Object.class); + private static final Reflection.MethodInvoker getName = Reflection.getTypedMethod(MinecraftKey.class, null, String.class); protected boolean tileEntityVisible(Set hiddenBlockEntities, Object tile) { - return !hiddenBlockEntities.contains(IRegistry.aa.b(entityType.get(tile)).a()); + return !hiddenBlockEntities.contains((String) getName.invoke(getKey.invoke(tileEntityTypes, entityType.get(tile)))); } private byte[] dataHider(int obfuscationTarget, Set obfuscate, byte[] data, int sections) { diff --git a/SpigotCore_19/src/de/steamwar/techhider/ChunkHider19.java b/SpigotCore_19/src/de/steamwar/techhider/ChunkHider19.java deleted file mode 100644 index 0ebba1c..0000000 --- a/SpigotCore_19/src/de/steamwar/techhider/ChunkHider19.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.techhider; - -import net.minecraft.core.IRegistry; - -import java.util.Set; - -public class ChunkHider19 extends ChunkHider18 { - @Override - protected boolean tileEntityVisible(Set hiddenBlockEntities, Object tile) { - return !hiddenBlockEntities.contains(IRegistry.ab.b(entityType.get(tile)).a()); - } -} diff --git a/SpigotCore_9/src/de/steamwar/core/CraftbukkitWrapper9.java b/SpigotCore_9/src/de/steamwar/core/CraftbukkitWrapper9.java index 6cce09e..8d111e3 100644 --- a/SpigotCore_9/src/de/steamwar/core/CraftbukkitWrapper9.java +++ b/SpigotCore_9/src/de/steamwar/core/CraftbukkitWrapper9.java @@ -19,22 +19,19 @@ package de.steamwar.core; -import net.minecraft.server.v1_9_R2.MinecraftServer; -import net.minecraft.server.v1_9_R2.PacketPlayOutMapChunk; -import org.bukkit.craftbukkit.v1_9_R2.CraftChunk; -import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer; +import com.comphenix.tinyprotocol.Reflection; +import com.comphenix.tinyprotocol.TinyProtocol; import org.bukkit.entity.Player; public class CraftbukkitWrapper9 implements CraftbukkitWrapper.ICraftbukkitWrapper { + private static final Class chunk = Reflection.getClass("{nms.world.level.chunk}.Chunk"); + private static final Class packetPlayOutMapChunk = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutMapChunk"); + private static final Reflection.ConstructorInvoker newPacketPlayOutMapChunk = Reflection.getConstructor(packetPlayOutMapChunk, chunk, int.class); + private static final Reflection.MethodInvoker getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle"); + @Override public void sendChunk(Player p, int chunkX, int chunkZ) { - ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunkX, chunkZ)).getHandle(), 65535)); - } - - @SuppressWarnings("deprecation") - @Override - public double[] getSpigotTPS() { - return MinecraftServer.getServer().recentTps; + TinyProtocol.instance.sendPacket(p, newPacketPlayOutMapChunk.invoke(getHandle.invoke(p.getWorld().getChunkAt(chunkX, chunkZ)), 65535)); } } diff --git a/SpigotCore_Main/src/de/steamwar/core/CraftbukkitWrapper.java b/SpigotCore_Main/src/de/steamwar/core/CraftbukkitWrapper.java index f3ad54e..13cd06a 100644 --- a/SpigotCore_Main/src/de/steamwar/core/CraftbukkitWrapper.java +++ b/SpigotCore_Main/src/de/steamwar/core/CraftbukkitWrapper.java @@ -28,6 +28,5 @@ public class CraftbukkitWrapper { public interface ICraftbukkitWrapper { void sendChunk(Player p, int chunkX, int chunkZ); - double[] getSpigotTPS(); } } diff --git a/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java index 826213c..54a5f7e 100644 --- a/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java +++ b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java @@ -19,6 +19,7 @@ package de.steamwar.core; +import com.comphenix.tinyprotocol.Reflection; import org.bukkit.Bukkit; public class TPSWatcher { @@ -78,8 +79,11 @@ public class TPSWatcher { } } + private static final Class minecraftServer = Reflection.getClass("{nms.server}.MinecraftServer"); + private static final Reflection.MethodInvoker getServer = Reflection.getTypedMethod(minecraftServer, "getServer", minecraftServer); + private static final Reflection.FieldAccessor recentTps = Reflection.getField(minecraftServer, "recentTps", double[].class); private static double[] getSpigotTPS() { - return CraftbukkitWrapper.impl.getSpigotTPS(); + return recentTps.get(getServer.invoke(null)); } private static double round(double d) { From 6becd709863dc41319225d8703bdc96a1307c72b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 1 Feb 2023 15:45:39 +0100 Subject: [PATCH 04/17] Fix CraftbukkitWrapper8 --- SpigotCore_8/src/de/steamwar/core/CraftbukkitWrapper8.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/SpigotCore_8/src/de/steamwar/core/CraftbukkitWrapper8.java b/SpigotCore_8/src/de/steamwar/core/CraftbukkitWrapper8.java index 149664c..23be791 100644 --- a/SpigotCore_8/src/de/steamwar/core/CraftbukkitWrapper8.java +++ b/SpigotCore_8/src/de/steamwar/core/CraftbukkitWrapper8.java @@ -19,7 +19,6 @@ package de.steamwar.core; -import net.minecraft.server.v1_8_R3.MinecraftServer; import net.minecraft.server.v1_8_R3.PacketPlayOutMapChunk; import org.bukkit.craftbukkit.v1_8_R3.CraftChunk; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; @@ -31,9 +30,4 @@ public class CraftbukkitWrapper8 implements CraftbukkitWrapper.ICraftbukkitWrapp public void sendChunk(Player p, int chunkX, int chunkZ) { ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunkX, chunkZ)).getHandle(), true, 65535)); } - - @Override - public double[] getSpigotTPS() { - return MinecraftServer.getServer().recentTps; - } } From 22359819f2d237b881691b401884e6f8ea2a6330 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 1 Feb 2023 16:29:34 +0100 Subject: [PATCH 05/17] Further generalisation --- .../src/de/steamwar/techhider/BlockIds14.java | 8 ++--- .../steamwar/techhider/ProtocolWrapper14.java | 2 +- .../steamwar/techhider/ProtocolWrapper18.java | 14 +++----- .../steamwar/techhider/ProtocolWrapper19.java | 35 +------------------ .../steamwar/techhider/ProtocolWrapper8.java | 9 +---- .../steamwar/techhider/ProtocolWrapper.java | 2 -- .../src/de/steamwar/techhider/TechHider.java | 8 ++++- 7 files changed, 17 insertions(+), 61 deletions(-) diff --git a/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java b/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java index f4be936..6e6ff1a 100644 --- a/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java +++ b/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java @@ -28,8 +28,6 @@ import java.util.Set; public class BlockIds14 implements BlockIds { - private static final Class iRegistry = Reflection.getClass("{nms.core}.IRegistry"); - private static final Class minecraftKey = Reflection.getClass("{nms.resources}.MinecraftKey"); private static final Class blockStateList = Reflection.getClass("{nms.world.level.block.state}.BlockStateList"); private static final Class fluidTypeFlowing = Reflection.getClass("{nms.world.level.material}.FluidTypeFlowing"); private static final Class fluid = Reflection.getClass("{nms.world.level.material}.Fluid"); @@ -63,11 +61,9 @@ public class BlockIds14 implements BlockIds { return ids; } - private static final Reflection.ConstructorInvoker newMinecraftkey = Reflection.getConstructor(minecraftKey, String.class); - private static final Reflection.MethodInvoker registryBlocksGet = Reflection.getTypedMethod(iRegistry, null, Object.class, minecraftKey); - private static final Object blockRegistry = Reflection.getField(iRegistry, Reflection.getClass("{nms.core}.RegistryBlocks"), 0, TechHider.block).get(null); + private static final Reflection.MethodInvoker getBlock = Reflection.getTypedMethod(TechHider.craftMagicNumbers, "getBlock", TechHider.block, Material.class); private Object getBlock(Material material) { - return registryBlocksGet.invoke(blockRegistry, newMinecraftkey.invoke(material.name().toLowerCase())); + return getBlock.invoke(null, material); } private static final Reflection.MethodInvoker getCombinedId = Reflection.getTypedMethod(TechHider.block, null, int.class, TechHider.iBlockData); diff --git a/SpigotCore_14/src/de/steamwar/techhider/ProtocolWrapper14.java b/SpigotCore_14/src/de/steamwar/techhider/ProtocolWrapper14.java index bb52f52..9b45405 100644 --- a/SpigotCore_14/src/de/steamwar/techhider/ProtocolWrapper14.java +++ b/SpigotCore_14/src/de/steamwar/techhider/ProtocolWrapper14.java @@ -40,7 +40,7 @@ public class ProtocolWrapper14 extends ProtocolWrapper8 { if(bypass.bypass(p, ProtocolUtils.posToChunk(TechHider.blockPositionX.get(pos)), ProtocolUtils.posToChunk(TechHider.blockPositionZ.get(pos)))) return packet; - if(ProtocolWrapper.impl.iBlockDataHidden(obfuscate, blockBreakBlockData.get(packet))){ + if(TechHider.iBlockDataHidden(obfuscate, blockBreakBlockData.get(packet))){ packet = blockBreakCloner.apply(packet); blockBreakBlockData.set(packet, obfuscationTarget); } diff --git a/SpigotCore_18/src/de/steamwar/techhider/ProtocolWrapper18.java b/SpigotCore_18/src/de/steamwar/techhider/ProtocolWrapper18.java index 7edbd8d..a52ddd5 100644 --- a/SpigotCore_18/src/de/steamwar/techhider/ProtocolWrapper18.java +++ b/SpigotCore_18/src/de/steamwar/techhider/ProtocolWrapper18.java @@ -20,9 +20,9 @@ package de.steamwar.techhider; import com.comphenix.tinyprotocol.Reflection; -import net.minecraft.core.IRegistry; import net.minecraft.core.SectionPosition; import net.minecraft.network.protocol.game.PacketPlayOutBlockBreak; +import net.minecraft.world.level.block.entity.TileEntitySign; import net.minecraft.world.level.block.entity.TileEntityTypes; import net.minecraft.world.level.block.state.IBlockData; import org.bukkit.Material; @@ -45,15 +45,16 @@ public class ProtocolWrapper18 implements ProtocolWrapper { return packet; packet = TechHider.multiBlockChangeCloner.apply(packet); - multiBlockChangeBlocks.set(packet, iBlockDataArrayCloner.apply(multiBlockChangeBlocks.get(packet), block -> ProtocolWrapper.impl.iBlockDataHidden(obfuscate, block) ? obfuscationTarget : block)); + multiBlockChangeBlocks.set(packet, iBlockDataArrayCloner.apply(multiBlockChangeBlocks.get(packet), block -> TechHider.iBlockDataHidden(obfuscate, block) ? obfuscationTarget : block)); return packet; }; } private static final Reflection.FieldAccessor tileEntityType = Reflection.getField(TechHider.tileEntityDataPacket, TileEntityTypes.class, 0); + private static final TileEntityTypes signType = Reflection.getField(TileEntityTypes.class, TileEntityTypes.class, 0, TileEntitySign.class).get(null); @Override public boolean unfilteredTileEntityDataAction(Object packet) { - return tileEntityType.get(packet) != TileEntityTypes.h; + return tileEntityType.get(packet) != signType; } @Override @@ -63,15 +64,10 @@ public class ProtocolWrapper18 implements ProtocolWrapper { if(bypass.bypass(p, ProtocolUtils.posToChunk(TechHider.blockPositionX.get(breakPacket.b())), ProtocolUtils.posToChunk(TechHider.blockPositionZ.get(breakPacket.b())))) return packet; - if(!ProtocolWrapper.impl.iBlockDataHidden(obfuscate, breakPacket.c())) + if(!TechHider.iBlockDataHidden(obfuscate, breakPacket.c())) return packet; return new PacketPlayOutBlockBreak(breakPacket.b(), (IBlockData) obfuscationTarget, breakPacket.d(), breakPacket.a()); }; } - - @Override - public boolean iBlockDataHidden(Set obfuscate, Object iBlockData) { - return obfuscate.contains(Material.getMaterial(IRegistry.U.b(((IBlockData) iBlockData).b()).a().toUpperCase())); - } } diff --git a/SpigotCore_19/src/de/steamwar/techhider/ProtocolWrapper19.java b/SpigotCore_19/src/de/steamwar/techhider/ProtocolWrapper19.java index 240f854..9c31653 100644 --- a/SpigotCore_19/src/de/steamwar/techhider/ProtocolWrapper19.java +++ b/SpigotCore_19/src/de/steamwar/techhider/ProtocolWrapper19.java @@ -19,49 +19,16 @@ package de.steamwar.techhider; -import com.comphenix.tinyprotocol.Reflection; -import net.minecraft.core.IRegistry; -import net.minecraft.core.SectionPosition; -import net.minecraft.world.level.block.entity.TileEntityTypes; -import net.minecraft.world.level.block.state.IBlockData; import org.bukkit.Material; import org.bukkit.entity.Player; import java.util.Set; import java.util.function.BiFunction; -import java.util.function.UnaryOperator; -public class ProtocolWrapper19 implements ProtocolWrapper { - - private static final Reflection.FieldAccessor multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, SectionPosition.class, 0); - private static final Reflection.FieldAccessor multiBlockChangeBlocks = Reflection.getField(TechHider.multiBlockChangePacket, IBlockData[].class, 0); - private static final BiFunction, Object> iBlockDataArrayCloner = ProtocolUtils.arrayCloneGenerator(TechHider.iBlockData); - @Override - public BiFunction multiBlockChangeGenerator(Object obfuscationTarget, Set obfuscate, TechHider.BypassEvaluator bypass) { - return (p, packet) -> { - Object chunkCoords = multiBlockChangeChunk.get(packet); - if(bypass.bypass(p, TechHider.blockPositionX.get(chunkCoords), TechHider.blockPositionZ.get(chunkCoords))) - return packet; - - packet = TechHider.multiBlockChangeCloner.apply(packet); - multiBlockChangeBlocks.set(packet, iBlockDataArrayCloner.apply(multiBlockChangeBlocks.get(packet), block -> ProtocolWrapper.impl.iBlockDataHidden(obfuscate, block) ? obfuscationTarget : block)); - return packet; - }; - } - - private static final Reflection.FieldAccessor tileEntityType = Reflection.getField(TechHider.tileEntityDataPacket, TileEntityTypes.class, 0); - @Override - public boolean unfilteredTileEntityDataAction(Object packet) { - return tileEntityType.get(packet) != TileEntityTypes.h; - } +public class ProtocolWrapper19 extends ProtocolWrapper18 { @Override public BiFunction blockBreakHiderGenerator(Class blockBreakPacket, Object obfuscationTarget, Set obfuscate, TechHider.BypassEvaluator bypass) { return null; } - - @Override - public boolean iBlockDataHidden(Set obfuscate, Object iBlockData) { - return obfuscate.contains(Material.getMaterial(IRegistry.V.b(((IBlockData) iBlockData).b()).a().toUpperCase())); - } } diff --git a/SpigotCore_8/src/de/steamwar/techhider/ProtocolWrapper8.java b/SpigotCore_8/src/de/steamwar/techhider/ProtocolWrapper8.java index abc9e61..681b4f7 100644 --- a/SpigotCore_8/src/de/steamwar/techhider/ProtocolWrapper8.java +++ b/SpigotCore_8/src/de/steamwar/techhider/ProtocolWrapper8.java @@ -48,7 +48,7 @@ public class ProtocolWrapper8 implements ProtocolWrapper { Object modpacket = TechHider.multiBlockChangeCloner.apply(packet); multiBlockChangeInfos.set(modpacket, multiBlockChangeInfoArrayCloner.apply(multiBlockChangeInfos.get(modpacket), mbci -> { - if(ProtocolWrapper.impl.iBlockDataHidden(obfuscate, multiBlockChangeInfoBlock.get(mbci))) + if(TechHider.iBlockDataHidden(obfuscate, multiBlockChangeInfoBlock.get(mbci))) return multiBlockChangeInfoConstructor.invoke(modpacket, multiBlockChangeInfoPos.get(mbci), obfuscationTarget); return mbci; })); @@ -66,11 +66,4 @@ public class ProtocolWrapper8 implements ProtocolWrapper { public BiFunction blockBreakHiderGenerator(Class blockBreakPacket, Object obfuscationTarget, Set obfuscate, TechHider.BypassEvaluator bypass) { return null; } - - private static final Reflection.MethodInvoker getBlockByBlockData = Reflection.getTypedMethod(TechHider.iBlockData, null, TechHider.block); - private static final Reflection.MethodInvoker getMaterialByBlock = Reflection.getTypedMethod(TechHider.craftMagicNumbers, "getMaterial", Material.class, TechHider.block); - @Override - public boolean iBlockDataHidden(Set obfuscate, Object iBlockData) { - return obfuscate.contains((Material) getMaterialByBlock.invoke(null, getBlockByBlockData.invoke(iBlockData))); - } } diff --git a/SpigotCore_Main/src/de/steamwar/techhider/ProtocolWrapper.java b/SpigotCore_Main/src/de/steamwar/techhider/ProtocolWrapper.java index cc95e03..2e9e311 100644 --- a/SpigotCore_Main/src/de/steamwar/techhider/ProtocolWrapper.java +++ b/SpigotCore_Main/src/de/steamwar/techhider/ProtocolWrapper.java @@ -36,6 +36,4 @@ public interface ProtocolWrapper { BiFunction blockBreakHiderGenerator(Class blockBreakPacket, Object obfuscationTarget, Set obfuscate, TechHider.BypassEvaluator bypass); BiFunction multiBlockChangeGenerator(Object obfuscationTarget, Set obfuscate, TechHider.BypassEvaluator bypass); - - boolean iBlockDataHidden(Set obfuscate, Object iBlockData); } diff --git a/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java b/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java index 38f00ba..36e70b3 100644 --- a/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java +++ b/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java @@ -46,6 +46,12 @@ public class TechHider { public static final Class craftMagicNumbers = Reflection.getClass("{obc}.util.CraftMagicNumbers"); private static final Reflection.MethodInvoker getBlockByMaterial = Reflection.getTypedMethod(craftMagicNumbers, "getBlock", block, Material.class); + private static final Reflection.MethodInvoker getBlockByBlockData = Reflection.getTypedMethod(iBlockData, null, block); + private static final Reflection.MethodInvoker getMaterialByBlock = Reflection.getTypedMethod(craftMagicNumbers, "getMaterial", Material.class, block); + public static boolean iBlockDataHidden(Set obfuscate, Object iBlockData) { + return obfuscate.contains((Material) getMaterialByBlock.invoke(null, getBlockByBlockData.invoke(iBlockData))); + } + private final Map, BiFunction> techhiders = new HashMap<>(); private final BypassEvaluator bypass; private final Object obfuscationTarget; @@ -94,7 +100,7 @@ public class TechHider { if(bypass.bypass(p, ProtocolUtils.posToChunk(blockPositionX.get(pos)), ProtocolUtils.posToChunk(blockPositionZ.get(pos)))) return packet; - if(ProtocolWrapper.impl.iBlockDataHidden(obfuscate, blockChangeBlockData.get(packet))) { + if(iBlockDataHidden(obfuscate, blockChangeBlockData.get(packet))) { packet = blockChangeCloner.apply(packet); blockChangeBlockData.set(packet, obfuscationTarget); } From 32d3bddc39adaedc21458fea33525407a230928d Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 2 Feb 2023 08:40:16 +0100 Subject: [PATCH 06/17] Bugfix ChunkHider18 --- SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java b/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java index e994f63..9dde1ad 100644 --- a/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java +++ b/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java @@ -77,7 +77,7 @@ public class ChunkHider18 implements ChunkHider { public static final Class tileEntity = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$a"); protected static final Reflection.FieldAccessor entityType = Reflection.getField(tileEntity, TileEntityTypes.class, 0); - private static final IRegistry> tileEntityTypes = (IRegistry>) Reflection.getField(IRegistry.class, IRegistry.class, 0, TileEntityTypes.class); + private static final IRegistry tileEntityTypes = Reflection.getField(IRegistry.class, IRegistry.class, 0, TileEntityTypes.class).get(null); private static final Reflection.MethodInvoker getKey = Reflection.getTypedMethod(IRegistry.class, null, MinecraftKey.class, Object.class); private static final Reflection.MethodInvoker getName = Reflection.getTypedMethod(MinecraftKey.class, null, String.class); protected boolean tileEntityVisible(Set hiddenBlockEntities, Object tile) { From e39e128aa69635c2c4c888c5fbd86c7d5602d092 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 5 Feb 2023 19:17:25 +0100 Subject: [PATCH 07/17] prevent double filter --- SpigotCore_Main/src/de/steamwar/entity/REntityServer.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index ecc59c7..a718c41 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -76,8 +76,11 @@ public class REntityServer implements Listener { } public void setCallback(EntityActionListener callback) { + boolean uninitialized = this.callback == null; this.callback = callback; - TinyProtocol.instance.addFilter(useEntity, filter); + + if(uninitialized) + TinyProtocol.instance.addFilter(useEntity, filter); } public void addPlayer(Player player) { From ca4c31a353afc7df63a6fd1ba4bdf503d4c88344 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 8 Feb 2023 21:29:11 +0100 Subject: [PATCH 08/17] Hotfix REntityServer --- SpigotCore_Main/src/de/steamwar/entity/REntityServer.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index e0ea912..5987112 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -23,7 +23,6 @@ import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.Core; import de.steamwar.core.FlatteningWrapper; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -49,7 +48,7 @@ public class REntityServer implements Listener { private static final Class useEntity = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity"); private static final Reflection.FieldAccessor useEntityTarget = Reflection.getField(useEntity, int.class, 0); - private static final Reflection.FieldAccessor useEntityAction = Reflection.getField(useEntity, int.class, 1); + //private static final Reflection.FieldAccessor useEntityAction = Reflection.getField(useEntity, int.class, 1); private final ConcurrentHashMap entityMap = new ConcurrentHashMap<>(); private final HashMap> entities = new HashMap<>(); @@ -65,10 +64,10 @@ public class REntityServer implements Listener { REntity entity = entityMap.get(target); if (entity == null) return packet; - EntityAction action = useEntityAction.get(packet) == 1 ? EntityAction.ATTACK : EntityAction.INTERACT; + /*EntityAction action = useEntityAction.get(packet) == 1 ? EntityAction.ATTACK : EntityAction.INTERACT; Bukkit.getScheduler().runTask(Core.getInstance(), () -> { callback.onAction(player, entity, action); - }); + });*/ return null; }; From 4efd305bf90c0d8fca28e165440bad306f3a0419 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 8 Feb 2023 21:44:11 +0100 Subject: [PATCH 09/17] Add debug output --- SpigotCore_Main/src/de/steamwar/techhider/TechHider.java | 1 + 1 file changed, 1 insertion(+) diff --git a/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java b/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java index 36e70b3..9373a76 100644 --- a/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java +++ b/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java @@ -49,6 +49,7 @@ public class TechHider { private static final Reflection.MethodInvoker getBlockByBlockData = Reflection.getTypedMethod(iBlockData, null, block); private static final Reflection.MethodInvoker getMaterialByBlock = Reflection.getTypedMethod(craftMagicNumbers, "getMaterial", Material.class, block); public static boolean iBlockDataHidden(Set obfuscate, Object iBlockData) { + System.out.println(iBlockData.getClass() + " " + getBlockByBlockData.invoke(iBlockData).getClass()); return obfuscate.contains((Material) getMaterialByBlock.invoke(null, getBlockByBlockData.invoke(iBlockData))); } From 22f598753e8f5dfb28594b5c27dfe061365f2df1 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 8 Feb 2023 21:52:07 +0100 Subject: [PATCH 10/17] Fix getTypedMethod recursion --- SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java b/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java index c3100b2..fc1e8c1 100644 --- a/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java +++ b/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java @@ -251,7 +251,7 @@ public final class Reflection { // Search in every superclass if (clazz.getSuperclass() != null) - return getMethod(clazz.getSuperclass(), methodName, params); + return getTypedMethod(clazz.getSuperclass(), methodName, returnType, params); throw new IllegalStateException(String.format("Unable to find method %s (%s).", methodName, Arrays.asList(params))); } From 76d16a2c0301c5e016e75a39500374fd23ae79c4 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 8 Feb 2023 21:52:24 +0100 Subject: [PATCH 11/17] Remove debug code --- SpigotCore_Main/src/de/steamwar/techhider/TechHider.java | 1 - 1 file changed, 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java b/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java index 9373a76..36e70b3 100644 --- a/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java +++ b/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java @@ -49,7 +49,6 @@ public class TechHider { private static final Reflection.MethodInvoker getBlockByBlockData = Reflection.getTypedMethod(iBlockData, null, block); private static final Reflection.MethodInvoker getMaterialByBlock = Reflection.getTypedMethod(craftMagicNumbers, "getMaterial", Material.class, block); public static boolean iBlockDataHidden(Set obfuscate, Object iBlockData) { - System.out.println(iBlockData.getClass() + " " + getBlockByBlockData.invoke(iBlockData).getClass()); return obfuscate.contains((Material) getMaterialByBlock.invoke(null, getBlockByBlockData.invoke(iBlockData))); } From 61341b815f8b17d6947cb2a751af59c0a57f6e09 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 8 Feb 2023 22:28:42 +0100 Subject: [PATCH 12/17] Fix EntityTypes --- .../src/de/steamwar/core/FlatteningWrapper14.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java b/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java index e650a29..8996475 100644 --- a/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java +++ b/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java @@ -22,6 +22,7 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.Reflection; import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -325,9 +326,13 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper return displayName != null ? Optional.of(ChatWrapper.impl.stringToChatComponent(displayName)) : Optional.empty(); } - private static final Reflection.FieldAccessor spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, Reflection.getClass("{nms.world.entity}.EntityTypes"), 0); + private static final Class registryBlocks = Reflection.getClass("{nms.core}.RegistryBlocks"); + private static final Class entityTypes = Reflection.getClass("{nms.world.entity}.EntityTypes"); + private static final Object entityTypesRegistry = Reflection.getField(Reflection.getClass("{nms.core}.IRegistry"), registryBlocks, 0, entityTypes).get(null); + private static final Reflection.MethodInvoker get = Reflection.getMethod(registryBlocks, null, Reflection.getClass("{nms.resources}.MinecraftKey")); + private static final Reflection.FieldAccessor spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, entityTypes, 0); private static final Reflection.FieldAccessor spawnLivingType = Core.getVersion() > 19 ? spawnType : Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1); - private static final Reflection.MethodInvoker getEntityTypes = Reflection.getMethod("{obc}.util.CraftMagicNumbers", "getEntityTypes", EntityType.class); + private static final Reflection.MethodInvoker toMinecraft = Reflection.getMethod("{obc}.util.CraftNamespacedKey", "toMinecraft", NamespacedKey.class); private static final Map types = new HashMap<>(); static { types.put(EntityType.ARMOR_STAND, 1); @@ -335,9 +340,9 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper @Override public void setSpawnPacketType(Object packet, EntityType type) { if(type.isAlive()) { - spawnLivingType.set(packet, Core.getVersion() > 18 ? getEntityTypes.invoke(null, type) : types.get(type)); + spawnLivingType.set(packet, Core.getVersion() > 18 ? get.invoke(entityTypesRegistry, toMinecraft.invoke(null, type.getKey())) : types.get(type)); } else { - spawnType.set(packet, getEntityTypes.invoke(null, type)); + spawnType.set(packet, get.invoke(entityTypesRegistry, toMinecraft.invoke(null, type.getKey()))); } } From 91e2a9a619cc44950ffae528d55779bef23c5d46 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 16 Feb 2023 13:53:05 +0100 Subject: [PATCH 13/17] Hotfix: SchematicSelector --- .../src/de/steamwar/inventory/SchematicSelector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java index e57ef68..ed3f856 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java @@ -163,7 +163,7 @@ public class SchematicSelector { } if(!singleDirOpen) { if(NodeMember.getNodeMember(parent.getId(), user.getId()) != null) { - return Optional.ofNullable(SchematicNode.byIdAndUser(user, parent.getId())).flatMap(SchematicNode::getOptionalParent).map(integer -> SchematicNode.byIdAndUser(user, integer)).orElse(null); + return NodeMember.getNodeMember(parent.getId(), user.getId()).getParent().map(integer -> SchematicNode.byIdAndUser(user, integer)).orElse(null); } else { return getParent(parent).orElse(null); } From c3087948b528bc28d277bab36c76d3db379c7fb9 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 17 Feb 2023 15:11:53 +0100 Subject: [PATCH 14/17] Anti NoCom DOS --- .../src/de/steamwar/core/Core.java | 7 ++- .../de/steamwar/core/events/AntiNocom.java | 50 +++++++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java diff --git a/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore_Main/src/de/steamwar/core/Core.java index ff0d555..d1e6949 100644 --- a/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -22,10 +22,7 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.command.*; import de.steamwar.core.authlib.AuthlibInjector; -import de.steamwar.core.events.ChattingEvent; -import de.steamwar.core.events.PartialChunkFixer; -import de.steamwar.core.events.PlayerJoinedEvent; -import de.steamwar.core.events.WorldLoadEvent; +import de.steamwar.core.events.*; import de.steamwar.message.Message; import de.steamwar.network.NetworkReceiver; import de.steamwar.network.handlers.ServerDataHandler; @@ -99,6 +96,8 @@ public class Core extends JavaPlugin{ AuthlibInjector.inject(); TinyProtocol.init(); + new AntiNocom(); + if(Core.getVersion() < 17 && Bukkit.getPluginManager().getPlugin("ViaVersion") != null) new PartialChunkFixer(); diff --git a/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java b/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java new file mode 100644 index 0000000..cb509ad --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java @@ -0,0 +1,50 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.core.events; + +import com.comphenix.tinyprotocol.Reflection; +import com.comphenix.tinyprotocol.TinyProtocol; +import de.steamwar.core.Core; +import de.steamwar.sql.SWException; +import de.steamwar.techhider.ProtocolUtils; +import de.steamwar.techhider.TechHider; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class AntiNocom { + + public AntiNocom() { + TinyProtocol.instance.addFilter(blockDig, this::onDig); + } + + private static final Class blockDig = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockDig"); + private static final Reflection.FieldAccessor digPosition = Reflection.getField(blockDig, TechHider.blockPosition, 0); + private Object onDig(Player player, Object packet) { + Object pos = digPosition.get(packet); + int x = TechHider.blockPositionX.get(pos); + int z = TechHider.blockPositionZ.get(pos); + if(!player.getWorld().isChunkLoaded(ProtocolUtils.posToChunk(x), ProtocolUtils.posToChunk(z))) { + Bukkit.getScheduler().runTask(Core.getInstance(), () -> player.kickPlayer(null)); + SWException.log(player.getName() + " kicked for digging an unloaded block (potential NoCom-DOS attack)", ""); + return null; + } + return packet; + } +} From d3c27dd0f291af06ea088c353e6086caf7e068cf Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 17 Feb 2023 15:31:37 +0100 Subject: [PATCH 15/17] Add more debug code --- SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java b/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java index cb509ad..63b289c 100644 --- a/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java +++ b/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java @@ -42,7 +42,7 @@ public class AntiNocom { int z = TechHider.blockPositionZ.get(pos); if(!player.getWorld().isChunkLoaded(ProtocolUtils.posToChunk(x), ProtocolUtils.posToChunk(z))) { Bukkit.getScheduler().runTask(Core.getInstance(), () -> player.kickPlayer(null)); - SWException.log(player.getName() + " kicked for digging an unloaded block (potential NoCom-DOS attack)", ""); + SWException.log(player.getName() + " kicked for digging an unloaded block (potential NoCom-DOS attack)", x + " " + z); return null; } return packet; From 022b0983b6f9f45ab59f95b8fb8cc9c15ad0079c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 17 Feb 2023 15:34:08 +0100 Subject: [PATCH 16/17] Fix NoCom detection (dropping blocks) --- SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java b/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java index 63b289c..aea52b2 100644 --- a/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java +++ b/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java @@ -40,7 +40,7 @@ public class AntiNocom { Object pos = digPosition.get(packet); int x = TechHider.blockPositionX.get(pos); int z = TechHider.blockPositionZ.get(pos); - if(!player.getWorld().isChunkLoaded(ProtocolUtils.posToChunk(x), ProtocolUtils.posToChunk(z))) { + if((x != 0 || z != 0) && !player.getWorld().isChunkLoaded(ProtocolUtils.posToChunk(x), ProtocolUtils.posToChunk(z))) { Bukkit.getScheduler().runTask(Core.getInstance(), () -> player.kickPlayer(null)); SWException.log(player.getName() + " kicked for digging an unloaded block (potential NoCom-DOS attack)", x + " " + z); return null; From efbed65ab43d5c82a3669161c1f3fcf7a5042d8d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 18 Feb 2023 14:07:00 +0100 Subject: [PATCH 17/17] Update CommonCore --- CommonCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore b/CommonCore index 89b0c14..aa70f42 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 89b0c14da664589a7c9699d73bf72028cdf9dd0d +Subproject commit aa70f423d87e9f6534ad2dd1f20a5122179c423f