From a0f59e1a10ae8b8386ec0485abcc03a81af06e20 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 1 Feb 2023 15:42:08 +0100 Subject: [PATCH] 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) {