1.18 #323
@ -20,7 +20,6 @@
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
@ -39,7 +38,7 @@ public class ProtocolWrapper12 extends ProtocolWrapper8 {
|
||||
if(TechHider.bypass(p, TechHider.posToChunk(TechHider.blockPositionX.get(pos)), TechHider.posToChunk(TechHider.blockPositionZ.get(pos))))
|
||||
return packet;
|
||||
|
||||
if(Config.HiddenBlocks.contains(TechHider.getMaterialByIBlockData(blockBreakBlockData.get(packet)).name().toLowerCase())){
|
||||
if(ProtocolWrapper.impl.iBlockDataHidden(blockBreakBlockData.get(packet))){
|
||||
packet = blockBreakCloner.apply(packet);
|
||||
blockBreakBlockData.set(packet, TechHider.obfuscateIBlockData);
|
||||
}
|
||||
|
@ -55,6 +55,12 @@
|
||||
<version>4.1.68.Final</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mojang</groupId>
|
||||
<artifactId>authlib</artifactId>
|
||||
<version>1.5.25</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>steamwar</groupId>
|
||||
<artifactId>Spigot</artifactId>
|
||||
|
@ -20,9 +20,13 @@
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.record.REntity;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.core.SectionPosition;
|
||||
import net.minecraft.network.protocol.game.PacketPlayOutBlockBreak;
|
||||
import net.minecraft.world.entity.EntityTypes;
|
||||
import net.minecraft.world.level.block.entity.TileEntityTypes;
|
||||
@ -79,10 +83,8 @@ public class ProtocolWrapper18 implements ProtocolWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
private static final Class<?> sectionPosition = Reflection.getClass("{nms.core}.SectionPosition");
|
||||
private static final Reflection.FieldAccessor<?> multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, sectionPosition, 0);
|
||||
private static final Class<?> iBlockDataArray = Reflection.getClass("[L{nms.world.level.block.state}.IBlockData;");
|
||||
private static final Reflection.FieldAccessor<?> multiBlockChangeBlocks = Reflection.getField(TechHider.multiBlockChangePacket, iBlockDataArray, 0);
|
||||
private static final Reflection.FieldAccessor<SectionPosition> multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, SectionPosition.class, 0);
|
||||
private static final Reflection.FieldAccessor<IBlockData[]> multiBlockChangeBlocks = Reflection.getField(TechHider.multiBlockChangePacket, IBlockData[].class, 0);
|
||||
private static final BiFunction<Object, UnaryOperator<Object>, Object> iBlockDataArrayCloner = ProtocolAPI.arrayCloneGenerator(TechHider.iBlockData);
|
||||
@Override
|
||||
public Object multiBlockChangeHider(Player p, Object packet) {
|
||||
@ -90,9 +92,9 @@ public class ProtocolWrapper18 implements ProtocolWrapper {
|
||||
if(TechHider.bypass(p, TechHider.blockPositionX.get(chunkCoords), TechHider.blockPositionZ.get(chunkCoords)))
|
||||
return packet;
|
||||
|
||||
Object modpacket = TechHider.multiBlockChangeCloner.apply(packet);
|
||||
multiBlockChangeBlocks.set(modpacket, iBlockDataArrayCloner.apply(multiBlockChangeBlocks.get(modpacket), block -> Config.HiddenBlocks.contains(TechHider.getMaterialByIBlockData(block).name().toLowerCase()) ? TechHider.obfuscateIBlockData : block));
|
||||
return modpacket;
|
||||
packet = TechHider.multiBlockChangeCloner.apply(packet);
|
||||
multiBlockChangeBlocks.set(packet, iBlockDataArrayCloner.apply(multiBlockChangeBlocks.get(packet), block -> ProtocolWrapper.impl.iBlockDataHidden(block) ? TechHider.obfuscateIBlockData : block));
|
||||
return packet;
|
||||
}
|
||||
|
||||
private static final Reflection.FieldAccessor<TileEntityTypes> tileEntityType = Reflection.getField(TechHider.tileEntityDataPacket, TileEntityTypes.class, 0);
|
||||
@ -108,10 +110,21 @@ public class ProtocolWrapper18 implements ProtocolWrapper {
|
||||
if(TechHider.bypass(p, TechHider.posToChunk(TechHider.blockPositionX.get(breakPacket.b())), TechHider.posToChunk(TechHider.blockPositionZ.get(breakPacket.b()))))
|
||||
return packet;
|
||||
|
||||
if(!Config.HiddenBlocks.contains(TechHider.getMaterialByIBlockData(breakPacket.c()).name().toLowerCase()))
|
||||
if(!ProtocolWrapper.impl.iBlockDataHidden(breakPacket.c()))
|
||||
return packet;
|
||||
|
||||
return new PacketPlayOutBlockBreak(breakPacket.b(), (IBlockData) TechHider.obfuscateIBlockData, breakPacket.d(), breakPacket.a());
|
||||
};
|
||||
}
|
||||
|
||||
private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(Fight.playerInfoDataClass, GameProfile.class, int.class, Fight.enumGamemode, Fight.iChatBaseComponent);
|
||||
@Override
|
||||
public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) {
|
||||
return playerInfoDataConstructor.invoke(profile, 0, mode, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean iBlockDataHidden(Object iBlockData) {
|
||||
return Config.HiddenBlocks.contains(IRegistry.X.b(((IBlockData) iBlockData).b()).a());
|
||||
}
|
||||
}
|
||||
|
@ -23,9 +23,10 @@ import com.comphenix.tinyprotocol.Reflection;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.UnpooledByteBufAllocator;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData;
|
||||
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
|
||||
import net.minecraft.world.entity.EntityTypes;
|
||||
import net.minecraft.world.level.block.entity.TileEntityTypes;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -54,7 +55,7 @@ public class TechHider18 implements TechHider.ChunkHider {
|
||||
private static final Reflection.FieldAccessor<byte[]> dataField = Reflection.getField(ClientboundLevelChunkPacketData.class, byte[].class, 0);
|
||||
private static final Reflection.FieldAccessor<List> tileEntities = Reflection.getField(ClientboundLevelChunkPacketData.class, List.class, 0);
|
||||
public static final Class<?> tileEntity = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$a");
|
||||
private static final Reflection.FieldAccessor<EntityTypes> entityType = Reflection.getField(tileEntity, EntityTypes.class, 0);
|
||||
private static final Reflection.FieldAccessor<TileEntityTypes> entityType = Reflection.getField(tileEntity, TileEntityTypes.class, 0);
|
||||
|
||||
private final Set<Integer> hiddenBlockIds = BlockIdWrapper.impl.getHiddenBlockIds();
|
||||
private final int obfuscateWith = BlockIdWrapper.impl.getObfuscateWith();
|
||||
@ -67,13 +68,12 @@ public class TechHider18 implements TechHider.ChunkHider {
|
||||
packet = chunkPacketCloner.apply(packet);
|
||||
Object data = chunkDataCloner.apply(chunkData.get(packet));
|
||||
|
||||
tileEntities.set(packet, ((List<?>)tileEntities.get(packet)).stream().filter(
|
||||
tile -> Config.HiddenBlockEntities.contains(entityType.get(tile).i()) //TODO: i()?
|
||||
tileEntities.set(data, ((List<?>)tileEntities.get(data)).stream().filter(
|
||||
tile -> Config.HiddenBlockEntities.contains(IRegistry.ad.b(entityType.get(tile)).a())
|
||||
).collect(Collectors.toList()));
|
||||
|
||||
World world = p.getWorld();
|
||||
int sections = (world.getMaxHeight() - world.getMinHeight()) / 16;
|
||||
System.out.println(sections); //TODO
|
||||
dataField.set(data, dataHider(dataField.get(data), sections));
|
||||
|
||||
chunkData.set(packet, data);
|
||||
@ -85,6 +85,9 @@ public class TechHider18 implements TechHider.ChunkHider {
|
||||
int i = 0;
|
||||
|
||||
while(sections-- > 0) {
|
||||
buffer.writeBytes(data, i, 2); // Block count
|
||||
i += 2;
|
||||
|
||||
i = containerWalker(data, buffer, i, 15, blockId -> hiddenBlockIds.contains(blockId) ? obfuscateWith : blockId, (curI, dataArrayLength, bitsPerBlock) -> {
|
||||
if(bitsPerBlock < 15) {
|
||||
buffer.writeBytes(data, curI, dataArrayLength * 8);
|
||||
@ -115,7 +118,11 @@ public class TechHider18 implements TechHider.ChunkHider {
|
||||
byte bitsPerBlock = data[i++];
|
||||
buffer.writeByte(bitsPerBlock);
|
||||
|
||||
if(bitsPerBlock < globalPalette) {
|
||||
if(bitsPerBlock == 0) {
|
||||
int paletteValue = TechHider.readVarInt(data, i);
|
||||
i += TechHider.readVarIntLength(data, i);
|
||||
buffer.writeBytes(TechHider.writeVarInt(palette.apply(paletteValue)));
|
||||
}else if(bitsPerBlock < globalPalette) {
|
||||
int paletteLength = TechHider.readVarInt(data, i);
|
||||
int paletteLengthLength = TechHider.readVarIntLength(data, i);
|
||||
buffer.writeBytes(data, i, paletteLengthLength);
|
||||
|
@ -20,9 +20,12 @@
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.record.REntity;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -122,7 +125,7 @@ public class ProtocolWrapper8 implements ProtocolWrapper {
|
||||
|
||||
Object modpacket = TechHider.multiBlockChangeCloner.apply(packet);
|
||||
multiBlockChangeInfos.set(modpacket, multiBlockChangeInfoArrayCloner.apply(multiBlockChangeInfos.get(modpacket), mbci -> {
|
||||
if(Config.HiddenBlocks.contains(TechHider.getMaterialByIBlockData(multiBlockChangeInfoBlock.get(mbci)).name().toLowerCase()))
|
||||
if(ProtocolWrapper.impl.iBlockDataHidden(multiBlockChangeInfoBlock.get(mbci)))
|
||||
return multiBlockChangeInfoConstructor.invoke(modpacket, multiBlockChangeInfoPos.get(mbci), TechHider.obfuscateIBlockData);
|
||||
return mbci;
|
||||
}));
|
||||
@ -139,4 +142,17 @@ public class ProtocolWrapper8 implements ProtocolWrapper {
|
||||
public BiFunction<Player, Object, Object> blockBreakHiderGenerator(Class<?> blockBreakPacket) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(Fight.playerInfoDataClass, Fight.playerInfoPacket, GameProfile.class, int.class, Fight.enumGamemode, Fight.iChatBaseComponent);
|
||||
@Override
|
||||
public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) {
|
||||
return playerInfoDataConstructor.invoke(packet, profile, 0, mode, null);
|
||||
}
|
||||
|
||||
private static final Reflection.MethodInvoker getBlockByBlockData = Reflection.getTypedMethod(TechHider.iBlockData, null, TechHider.block);
|
||||
private static final Reflection.MethodInvoker getMaterialByBlock = Reflection.getTypedMethod(TechHider.craftMagicNumbers, "getMaterial", Material.class, TechHider.block);
|
||||
@Override
|
||||
public boolean iBlockDataHidden(Object iBlockData) {
|
||||
return Config.HiddenBlocks.contains(((Material) getMaterialByBlock.invoke(null, getBlockByBlockData.invoke(iBlockData))).name().toLowerCase());
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.record.GlobalRecorder;
|
||||
import de.steamwar.fightsystem.utils.ProtocolAPI;
|
||||
import de.steamwar.fightsystem.utils.ProtocolWrapper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Sound;
|
||||
@ -131,20 +132,19 @@ public class Fight {
|
||||
}
|
||||
}
|
||||
|
||||
private static final Class<?> playerInfoPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo");
|
||||
public static final Class<?> playerInfoPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo");
|
||||
private static final Class<?> playerInfoActionClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$EnumPlayerInfoAction");
|
||||
public static final Object addPlayer = playerInfoActionClass.getEnumConstants()[0];
|
||||
private static final Reflection.FieldAccessor<?> playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0);
|
||||
private static final Object updateGamemode = playerInfoActionClass.getEnumConstants()[1];
|
||||
public static final Object removePlayer = playerInfoActionClass.getEnumConstants()[4];
|
||||
private static final Reflection.FieldAccessor<List> playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0);
|
||||
private static final Class<?> playerInfoDataClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$PlayerInfoData");
|
||||
private static final Class<?> enumGamemode = Reflection.getClass(Core.getVersion() > 9 ? "{nms.world.level}.EnumGamemode" : "{nms}.WorldSettings$EnumGamemode");
|
||||
public static final Object creative = enumGamemode.getEnumConstants()[2];
|
||||
private static final Object spectator = enumGamemode.getEnumConstants()[4];
|
||||
private static final Class<?> iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent");
|
||||
public static final Class<?> playerInfoDataClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$PlayerInfoData");
|
||||
public static final Class<?> enumGamemode = Reflection.getClass(Core.getVersion() > 9 ? "{nms.world.level}.EnumGamemode" : "{nms}.WorldSettings$EnumGamemode");
|
||||
public static final Object creative = enumGamemode.getEnumConstants()[Core.getVersion() > 15 ? 1 : 2];
|
||||
private static final Object spectator = enumGamemode.getEnumConstants()[Core.getVersion() > 15 ? 3 : 4];
|
||||
public static final Class<?> iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent");
|
||||
|
||||
private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClass, playerInfoPacket, GameProfile.class, int.class, enumGamemode, iChatBaseComponent);
|
||||
public static void pseudoSpectator(Player player, boolean enable) {
|
||||
TinyProtocol.instance.sendPacket(player, playerInfoPacket(updateGamemode, new GameProfile(player.getUniqueId(), player.getName()), enable ? creative : spectator));
|
||||
}
|
||||
@ -152,7 +152,7 @@ public class Fight {
|
||||
public static Object playerInfoPacket(Object action, GameProfile profile, Object mode) {
|
||||
Object packet = ProtocolAPI.construct(playerInfoPacket);
|
||||
playerInfoAction.set(packet, action);
|
||||
playerInfoData.set(packet, Collections.singletonList(playerInfoDataConstructor.invoke(packet, profile, 0, mode, null)));
|
||||
playerInfoData.set(packet, Collections.singletonList(ProtocolWrapper.impl.playerInfoDataConstructor(packet, profile, mode)));
|
||||
return packet;
|
||||
}
|
||||
|
||||
|
@ -314,7 +314,7 @@ public class REntity {
|
||||
public static final Class<?> equipmentPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityEquipment");
|
||||
private static final Reflection.FieldAccessor<Integer> equipmentEntity = Reflection.getField(equipmentPacket, int.class, 0);
|
||||
|
||||
public static final Class<?> itemStack = Reflection.getClass("{nms}.ItemStack");
|
||||
public static final Class<?> itemStack = Reflection.getClass("{nms.world.item}.ItemStack");
|
||||
private static final Class<?> craftItemStack = Reflection.getClass("{obc}.inventory.CraftItemStack");
|
||||
private static final Reflection.MethodInvoker asNMSCopy = Reflection.getTypedMethod(REntity.craftItemStack, "asNMSCopy", REntity.itemStack, ItemStack.class);
|
||||
private Object getEquipmentPacket(String slot, ItemStack stack){
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import de.steamwar.core.VersionDependent;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@ -38,4 +39,8 @@ public interface ProtocolWrapper {
|
||||
boolean unfilteredTileEntityDataAction(Object packet);
|
||||
|
||||
BiFunction<Player, Object, Object> blockBreakHiderGenerator(Class<?> blockBreakPacket);
|
||||
|
||||
Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode);
|
||||
|
||||
boolean iBlockDataHidden(Object iBlockData);
|
||||
}
|
||||
|
@ -48,12 +48,10 @@ public class TechHider extends StateDependent {
|
||||
public static final Reflection.FieldAccessor<Integer> blockPositionZ = Reflection.getField(baseBlockPosition, int.class, 2);
|
||||
|
||||
public static final Class<?> iBlockData = Reflection.getClass("{nms.world.level.block.state}.IBlockData");
|
||||
private static final Class<?> block = Reflection.getClass("{nms.world.level.block}.Block");
|
||||
private static final Reflection.MethodInvoker getBlockByBlockData = Reflection.getTypedMethod(iBlockData, null, block);
|
||||
public static final Class<?> block = Reflection.getClass("{nms.world.level.block}.Block");
|
||||
private static final Reflection.MethodInvoker getBlockDataByBlock = Reflection.getTypedMethod(block, null, iBlockData);
|
||||
|
||||
private static final Class<?> craftMagicNumbers = Reflection.getClass("{obc}.util.CraftMagicNumbers");
|
||||
private static final Reflection.MethodInvoker getMaterialByBlock = Reflection.getTypedMethod(craftMagicNumbers, "getMaterial", Material.class, block);
|
||||
public static final Class<?> craftMagicNumbers = Reflection.getClass("{obc}.util.CraftMagicNumbers");
|
||||
private static final Reflection.MethodInvoker getBlockByMaterial = Reflection.getTypedMethod(craftMagicNumbers, "getBlock", block, Material.class);
|
||||
|
||||
public static final boolean ENABLED = !Config.OnlyPublicSchematics && !Config.test() && Config.TechhiderActive;
|
||||
@ -112,7 +110,7 @@ public class TechHider extends StateDependent {
|
||||
if(bypass(p, posToChunk(blockPositionX.get(pos)), posToChunk(blockPositionZ.get(pos))))
|
||||
return packet;
|
||||
|
||||
if(Config.HiddenBlocks.contains(getMaterialByIBlockData(blockChangeBlockData.get(packet)).name().toLowerCase())){
|
||||
if(ProtocolWrapper.impl.iBlockDataHidden(blockChangeBlockData.get(packet))) {
|
||||
packet = blockChangeCloner.apply(packet);
|
||||
blockChangeBlockData.set(packet, obfuscateIBlockData);
|
||||
}
|
||||
@ -176,10 +174,6 @@ public class TechHider extends StateDependent {
|
||||
}
|
||||
}
|
||||
|
||||
public static Material getMaterialByIBlockData(Object iBlockData) {
|
||||
return (Material) getMaterialByBlock.invoke(null, getBlockByBlockData.invoke(iBlockData));
|
||||
}
|
||||
|
||||
public static int posToChunk(int c){
|
||||
int chunk = c / 16;
|
||||
if(c<0)
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren