SteamWar/FightSystem
Archiviert
13
1

First tests (bugged for 1.15)

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2020-03-10 17:50:09 +01:00
Ursprung 0a82dc362f
Commit 04f4edbf30

Datei anzeigen

@ -17,6 +17,7 @@ import org.bukkit.craftbukkit.v1_12_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import static de.steamwar.fightsystem.utils.ITechHider.bypass; import static de.steamwar.fightsystem.utils.ITechHider.bypass;
@ -47,31 +48,24 @@ class TechHider_12 {
if(bypass(p, chunkX, chunkZ)) if(bypass(p, chunkX, chunkZ))
return; return;
PacketContainer cached = ITechHider.packetCache.get(packet); packet = packet.shallowClone();
if(cached != null){ e.setPacket(packet);
e.setPacket(cached); StructureModifier<List> list = packet.getSpecificModifier(List.class);
return;
}
cached = packet.deepClone();
ITechHider.packetCache.put(packet, cached);
e.setPacket(cached);
StructureModifier<List> list = cached.getSpecificModifier(List.class);
List nmsTags = list.read(0); List nmsTags = list.read(0);
boolean changed = false; boolean changed = false;
for(int i = nmsTags.size() - 1; i >= 0; i--){ List newNmsTags = new ArrayList(nmsTags.size());
NbtCompound nbt = NbtFactory.fromNMSCompound(nmsTags.get(i)); for(Object nmsTag : nmsTags){
if(Config.HiddenBlockEntities.contains(nbt.getString("id"))){ NbtCompound nbt = NbtFactory.fromNMSCompound(nmsTag);
nmsTags.remove(i); if(Config.HiddenBlockEntities.contains(nbt.getString("id")))
changed = true; changed = true;
else
newNmsTags.add(nmsTag);
} }
} if(changed)
if(changed){ list.write(0, newNmsTags);
list.write(0, nmsTags);
}
changed = false; changed = false;
StructureModifier<byte[]> byteArray = cached.getByteArrays(); StructureModifier<byte[]> byteArray = packet.getByteArrays();
byte [] data = byteArray.read(0); byte [] data = byteArray.read(0);
ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100); ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100);
int i = 0; int i = 0;
@ -91,20 +85,23 @@ class TechHider_12 {
int paletteLengthLength = ITechHider.readVarIntLength(data, i); int paletteLengthLength = ITechHider.readVarIntLength(data, i);
buffer.writeBytes(data, i, paletteLengthLength); buffer.writeBytes(data, i, paletteLengthLength);
i += paletteLengthLength; i += paletteLengthLength;
List<Integer> palette = new ArrayList<>(paletteLength);
for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){ for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){
int actPalette = ITechHider.readVarInt(data, i); palette.add(ITechHider.readVarInt(data, i));
int actPaletteLength = ITechHider.readVarIntLength(data, i); i += ITechHider.readVarIntLength(data, i);
}
int blockId = actPalette >> 4; int replacement = 0;
for(int entry : palette){
int blockId = entry >> 4;
if(Config.HiddenBlocks.contains(blockId)){ if(Config.HiddenBlocks.contains(blockId)){
byte[] a = ITechHider.writeVarInt(obfuscateShift4); while(palette.contains((++replacement) << 4));
buffer.writeBytes(a); entry = replacement << 4;
changed = true; changed = true;
}else{
buffer.writeBytes(data, i, actPaletteLength);
} }
i += actPaletteLength; buffer.writeBytes(ITechHider.writeVarInt(entry));
} }
int dataArrayLength = ITechHider.readVarInt(data, i); int dataArrayLength = ITechHider.readVarInt(data, i);
int dataArrayLengthLength = ITechHider.readVarIntLength(data, i); int dataArrayLengthLength = ITechHider.readVarIntLength(data, i);
buffer.writeBytes(data, i, dataArrayLength * 8 + dataArrayLengthLength); buffer.writeBytes(data, i, dataArrayLength * 8 + dataArrayLengthLength);