SteamWar/FightSystem
Archiviert
13
1

Techhider speed improvement

Dieser Commit ist enthalten in:
Lixfel 2019-09-25 18:21:20 +02:00
Ursprung 8459e187ea
Commit b6d622b170

Datei anzeigen

@ -16,6 +16,8 @@ import com.google.common.primitives.Bytes;
import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.UnpooledByteBufAllocator;
import javafx.util.Pair; import javafx.util.Pair;
import net.minecraft.server.v1_12_R1.PacketPlayOutMapChunk; import net.minecraft.server.v1_12_R1.PacketPlayOutMapChunk;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -105,45 +107,49 @@ public class TechHider {
changed = false; changed = false;
byte [] data = byteArray.read(0); byte [] data = byteArray.read(0);
List<Byte> newData = new ArrayList<>(Bytes.asList(data)); ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length);
int i = 0; int i = 0;
while(i < newData.size()){ while(i < data.length){
byte bitsPerBlock = newData.get(i++); byte bitsPerBlock = data[i++];
buffer.writeByte(bitsPerBlock);
if(bitsPerBlock < 4) if(bitsPerBlock < 4)
bitsPerBlock = 4; bitsPerBlock = 4;
else if(bitsPerBlock > 8){ else if(bitsPerBlock > 8){
bitsPerBlock = 13; bitsPerBlock = 13;
i++; i++;
buffer.writeByte(data[1]);
} }
if(bitsPerBlock != 13){ if(bitsPerBlock != 13){
int paletteLength = readVarInt(Bytes.toArray(newData), i); int paletteLength = readVarInt(data, i);
i += readVarIntLength(Bytes.toArray(newData), i); int paletteLengthLength = readVarIntLength(data, i);
buffer.writeBytes(data, i, paletteLengthLength);
i += paletteLengthLength;
for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){ for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){
int actPalette = readVarInt(Bytes.toArray(newData), i); int actPalette = readVarInt(data, i);
int actPaletteLength = readVarIntLength(Bytes.toArray(newData), i); int actPaletteLength = readVarIntLength(data, i);
int blockId = actPalette >> 4; int blockId = actPalette >> 4;
if(Config.HiddenBlocks.contains(blockId)){ if(Config.HiddenBlocks.contains(blockId)){
byte[] a = writeVarInt(obfuscateShift4); byte[] a = writeVarInt(obfuscateShift4);
for(int j = 0; j < actPaletteLength; j++){ buffer.writeBytes(a);
newData.remove(i);
}
for(byte b : a){
newData.add(i++, b);
}
changed = true; changed = true;
}else{ }else{
i += actPaletteLength; buffer.writeBytes(data, i, actPaletteLength);
} }
i += actPaletteLength;
} }
int dataArrayLength = readVarInt(Bytes.toArray(newData), i); int dataArrayLength = readVarInt(data, i);
i += readVarIntLength(Bytes.toArray(newData), i); int dataArrayLengthLength = readVarIntLength(data, i);
buffer.writeBytes(data, i, dataArrayLength * 8 + dataArrayLengthLength);
i += dataArrayLengthLength;
i += dataArrayLength * 8; i += dataArrayLength * 8;
}else{ }else{
int dataArrayLength = readVarInt(Bytes.toArray(newData), i); int dataArrayLength = readVarInt(data, i);
i += readVarIntLength(Bytes.toArray(newData), i); int dataArrayLengthLength = readVarIntLength(data, i);
buffer.writeBytes(data, i, dataArrayLength*8 + dataArrayLengthLength);
i += dataArrayLengthLength;
/*int arrayEnd = dataArrayLength * 8 + i; /*int arrayEnd = dataArrayLength * 8 + i;
int bitsOver = 8; //9 bits (id) + 4 bits (metadata) int bitsOver = 8; //9 bits (id) + 4 bits (metadata)
while(i < arrayEnd){ while(i < arrayEnd){
@ -165,11 +171,13 @@ public class TechHider {
i += dataArrayLength * 8; i += dataArrayLength * 8;
} }
buffer.writeBytes(data, i, 4096);
i += 4096; //Skylight (Not in Nether/End!!!) 2048 + Blocklight 2048 i += 4096; //Skylight (Not in Nether/End!!!) 2048 + Blocklight 2048
} }
if(changed){ if(changed){
byteArray.write(0, Bytes.toArray(newData)); buffer.readBytes(data);
byteArray.write(0, data);
} }
} }
}).start(4 * threadMultiplier); }).start(4 * threadMultiplier);
@ -349,7 +357,7 @@ public class TechHider {
} }
private static byte[] writeVarInt(int value) { private static byte[] writeVarInt(int value) {
ArrayList<Byte> buffer = new ArrayList<>(); List<Byte> buffer = new ArrayList<>(5);
do { do {
byte temp = (byte)(value & 0b01111111); byte temp = (byte)(value & 0b01111111);
// Note: >>> means that the sign bit is shifted with the rest of the number rather than being left alone // Note: >>> means that the sign bit is shifted with the rest of the number rather than being left alone