TechHider refactoring, simple Blocktagging

This commit is contained in:
Lixfel
2024-12-21 16:53:49 +01:00
parent 1b47700c19
commit 793fc31b5c
16 changed files with 269 additions and 208 deletions
@@ -24,7 +24,6 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.bukkit.entity.Player;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.function.BiFunction;
@@ -45,20 +44,19 @@ public class ChunkHider9 extends ChunkHider8 {
private static final Reflection.MethodInvoker nbtTagGetString = Reflection.getTypedMethod(nbtTagCompound, null, String.class, String.class);
@Override
public BiFunction<Player, Object, Object> chunkHiderGenerator(TechHider.LocationEvaluator locationEvaluator, int obfuscationTarget, Set<Integer> obfuscate, Set<String> hiddenBlockEntities) {
public BiFunction<Player, Object, Object> chunkHiderGenerator(TechHider techHider) {
return (p, packet) -> {
int chunkX = mapChunkX.get(packet);
int chunkZ = mapChunkZ.get(packet);
if (locationEvaluator.skipChunk(p, chunkX, chunkZ))
if (techHider.getLocationEvaluator().skipChunk(p, chunkX, chunkZ))
return packet;
packet = mapChunkCloner.apply(packet);
Set<String> hiddenBlockEntities = techHider.getHiddenBlockEntities();
mapChunkBlockEntities.set(packet, ((List<?>)mapChunkBlockEntities.get(packet)).stream().filter(
nbttag -> !hiddenBlockEntities.contains((String) nbtTagGetString.invoke(nbttag, "id"))
).collect(Collectors.toList()));
int xOffset = 16*chunkX;
int zOffset = 16*chunkZ;
int primaryBitMask = mapChunkBitMask.get(packet);
ByteBuf in = Unpooled.wrappedBuffer(mapChunkData.get(packet));
ByteBuf out = Unpooled.buffer(in.readableBytes() + 64);
@@ -66,8 +64,8 @@ public class ChunkHider9 extends ChunkHider8 {
if(((1 << chunkY) & primaryBitMask) == 0)
continue;
int yOffset = 16*chunkY;
dataHider((x, y, z) -> locationEvaluator.check(p, x+xOffset, y+yOffset, z+zOffset), obfuscationTarget, obfuscate, in, out, locationEvaluator.skipChunkSection(p, chunkX, chunkY, chunkZ), locationEvaluator.blockPrecise(p, chunkX, chunkY, chunkZ));
SectionHider section = new SectionHider(p, techHider, in, out, chunkX, chunkY, chunkZ);
dataHider(section);
}
byte[] data = new byte[out.readableBytes()];
out.readBytes(data);
@@ -77,51 +75,45 @@ public class ChunkHider9 extends ChunkHider8 {
};
}
protected void dataHider(PosEvaluator locationEvaluator, int obfuscationTarget, Set<Integer> obfuscate, ByteBuf in, ByteBuf out, boolean skip, boolean blockPrecise) {
byte bitsPerBlock = in.readByte();
out.writeByte(bitsPerBlock);
protected void dataHider(SectionHider section) {
section.copyBitsPerBlock();
section.processPalette();
int paletteTarget = ChunkHider.processPalette(obfuscationTarget, skip ? Collections.emptySet() : obfuscate, in, out);
if(bitsPerBlock < 13) {
obfuscationTarget = paletteTarget;
obfuscate = Collections.emptySet();
if(section.isSkipSection() || (!section.blockPrecise() && section.isPaletted())) { //section.getBitsPerBlock() < 9
section.skipDataArray();
} else {
processDataArray(section);
}
processDataArray(locationEvaluator, obfuscationTarget, obfuscate, in, out, bitsPerBlock, skip || (!blockPrecise && bitsPerBlock < 9));
out.writeBytes(in, 4096); //Skylight (Not in Nether/End!!!) 2048 + Blocklight 2048
section.getOut().writeBytes(section.getIn(), 4096); //Skylight (Not in Nether/End!!!) 2048 + Blocklight 2048
}
protected void processDataArray(PosEvaluator locationEvaluator, int obfuscationTarget, Set<Integer> obfuscate, ByteBuf in, ByteBuf out, int bitsPerBlock, boolean skip) {
int dataArrayLength = ProtocolUtils.readVarInt(in);
ProtocolUtils.writeVarInt(out, dataArrayLength);
protected void processDataArray(SectionHider section) {
VariableValueArray values = new VariableValueArray(section.getBitsPerBlock(), section.readDataArray());
if(skip) {
out.writeBytes(in, dataArrayLength*8);
return;
}
VariableValueArray values = new VariableValueArray(bitsPerBlock, dataArrayLength, in);
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
int pos = (((y * 16) + z) * 16) + x;
switch (locationEvaluator.test(x, y, z)) {
switch (section.test(x, y, z)) {
case SKIP:
break;
case CHECK:
if(!obfuscate.contains(values.get(pos)))
if(!section.getObfuscate().contains(values.get(pos)))
break;
case HIDE:
values.set(pos, section.getTarget());
break;
case HIDE_AIR:
default:
values.set(pos, obfuscationTarget);
values.set(pos, section.getAir());
}
}
}
}
for(long l : values.backing)
out.writeLong(l);
section.writeDataArray(values.backing);
}
private static class VariableValueArray {
@@ -129,13 +121,10 @@ public class ChunkHider9 extends ChunkHider8 {
private final int bitsPerValue;
private final long valueMask;
public VariableValueArray(int bitsPerEntry, int dataArrayLength, ByteBuf in) {
public VariableValueArray(int bitsPerEntry, long[] dataArray) {
this.bitsPerValue = bitsPerEntry;
this.valueMask = (1L << this.bitsPerValue) - 1;
this.backing = new long[dataArrayLength];
for(int i = 0; i < dataArrayLength; i++)
backing[i] = in.readLong();
this.backing = dataArray;
}
public int get(int index) {