SteamWar/FightSystem
Archiviert
13
1

Remove ITechHider

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2021-08-31 12:12:54 +02:00
Ursprung f61c6cbf6d
Commit 1c428cdacc
4 geänderte Dateien mit 92 neuen und 125 gelöschten Zeilen

Datei anzeigen

@ -37,7 +37,7 @@ import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import static de.steamwar.fightsystem.utils.ITechHider.bypass;
import static de.steamwar.fightsystem.utils.TechHider.bypass;
public class TechHider12 extends PacketAdapter {
@ -85,28 +85,28 @@ public class TechHider12 extends PacketAdapter {
buffer.writeByte(bitsPerBlock);
if(bitsPerBlock != 13){
int paletteLength = ITechHider.readVarInt(data, i);
int paletteLengthLength = ITechHider.readVarIntLength(data, i);
int paletteLength = TechHider.readVarInt(data, i);
int paletteLengthLength = TechHider.readVarIntLength(data, i);
buffer.writeBytes(data, i, paletteLengthLength);
i += paletteLengthLength;
for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){
int entry = ITechHider.readVarInt(data, i);
i += ITechHider.readVarIntLength(data, i);
int entry = TechHider.readVarInt(data, i);
i += TechHider.readVarIntLength(data, i);
if(hiddenBlockIds.contains(entry)){
entry = obfuscateWith;
changed = true;
}
buffer.writeBytes(ITechHider.writeVarInt(entry));
buffer.writeBytes(TechHider.writeVarInt(entry));
}
}else{
buffer.writeByte(data[++i]); //Empty palette
Bukkit.getLogger().log(Level.SEVERE, "Full chunk occured");
}
int dataArrayLength = ITechHider.readVarInt(data, i);
int dataArrayLengthLength = ITechHider.readVarIntLength(data, i);
int dataArrayLength = TechHider.readVarInt(data, i);
int dataArrayLengthLength = TechHider.readVarIntLength(data, i);
buffer.writeBytes(data, i, dataArrayLength*8 + dataArrayLengthLength);
i += dataArrayLengthLength;
i += dataArrayLength * 8;

Datei anzeigen

@ -37,7 +37,7 @@ import java.nio.LongBuffer;
import java.util.List;
import java.util.Set;
import static de.steamwar.fightsystem.utils.ITechHider.bypass;
import static de.steamwar.fightsystem.utils.TechHider.bypass;
public class TechHider14 extends PacketAdapter {
@ -97,16 +97,16 @@ public class TechHider14 extends PacketAdapter {
buffer.writeByte(bitsPerBlock);
if(bitsPerBlock < 9){
int paletteLength = ITechHider.readVarInt(data, i);
int paletteLengthLength = ITechHider.readVarIntLength(data, i);
int paletteLength = TechHider.readVarInt(data, i);
int paletteLengthLength = TechHider.readVarIntLength(data, i);
buffer.writeBytes(data, i, paletteLengthLength);
i += paletteLengthLength;
for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){
int blockId = ITechHider.readVarInt(data, i);
int actPaletteLength = ITechHider.readVarIntLength(data, i);
int blockId = TechHider.readVarInt(data, i);
int actPaletteLength = TechHider.readVarIntLength(data, i);
if(hiddenBlockIds.contains(blockId)){
buffer.writeBytes(ITechHider.writeVarInt(obfuscateWith));
buffer.writeBytes(TechHider.writeVarInt(obfuscateWith));
changed = true;
}else{
buffer.writeBytes(data, i, actPaletteLength);
@ -115,15 +115,15 @@ public class TechHider14 extends PacketAdapter {
}
//We modify only the chunk palette for performance reasons
int dataArrayLength = ITechHider.readVarInt(data, i);
int dataArrayLengthLength = ITechHider.readVarIntLength(data, i);
int dataArrayLength = TechHider.readVarInt(data, i);
int dataArrayLengthLength = TechHider.readVarIntLength(data, i);
buffer.writeBytes(data, i, dataArrayLength * 8 + dataArrayLengthLength);
i += dataArrayLengthLength;
i += dataArrayLength * 8;
}else{
//Full Chunk/no palette, so the chunk has to be crawled through
int dataArrayLength = ITechHider.readVarInt(data, i);
int dataArrayLengthLength = ITechHider.readVarIntLength(data, i);
int dataArrayLength = TechHider.readVarInt(data, i);
int dataArrayLengthLength = TechHider.readVarIntLength(data, i);
buffer.writeBytes(data, i, dataArrayLengthLength);
i += dataArrayLengthLength;

Datei anzeigen

@ -1,101 +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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.utils;
import com.google.common.primitives.Bytes;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class ITechHider {
private ITechHider (){}
static boolean bypass(Player p, int chunkX, int chunkZ){
if(p == FightSystem.getEventLeiter())
return true;
FightTeam ft = Fight.getPlayerTeam(p);
if(ft == null){
return Config.ArenaRegion.chunkOutside(chunkX, chunkZ);
}else if(ft.isBlue()){
return ft.canPlayerEntern(p) || Config.RedExtendRegion.chunkOutside(chunkX, chunkZ);
}else{
return ft.canPlayerEntern(p) || Config.BlueExtendRegion.chunkOutside(chunkX, chunkZ);
}
}
public static int posToChunk(int c){
int chunk = c / 16;
if(c<0)
chunk--;
return chunk;
}
static int readVarInt(byte[] array, int startPos) {
int numRead = 0;
int result = 0;
byte read;
do {
read = array[startPos + numRead];
int value = (read & 0b01111111);
result |= (value << (7 * numRead));
numRead++;
if (numRead > 5) {
break;
}
} while ((read & 0b10000000) != 0);
return result;
}
static int readVarIntLength(byte[] array, int startPos) {
int numRead = 0;
byte read;
do {
read = array[startPos + numRead];
numRead++;
if (numRead > 5) {
break;
}
} while ((read & 0b10000000) != 0);
return numRead;
}
static byte[] writeVarInt(int value) {
List<Byte> buffer = new ArrayList<>(5);
do {
byte temp = (byte)(value & 0b01111111);
// Note: >>> means that the sign bit is shifted with the rest of the number rather than being left alone
value >>>= 7;
if (value != 0) {
temp |= 0b10000000;
}
buffer.add(temp);
} while (value != 0);
return Bytes.toArray(buffer);
}
}

Datei anzeigen

@ -30,12 +30,15 @@ import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.ChunkCoordIntPair;
import com.comphenix.protocol.wrappers.MultiBlockChangeInfo;
import com.comphenix.protocol.wrappers.WrappedBlockData;
import com.google.common.primitives.Bytes;
import de.steamwar.core.Core;
import de.steamwar.core.events.ChunkListener;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.VersionDependent;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent;
import org.bukkit.Bukkit;
@ -45,8 +48,6 @@ import org.bukkit.entity.Player;
import java.util.*;
import static de.steamwar.fightsystem.utils.ITechHider.bypass;
public class TechHider extends StateDependent {
public static final boolean ENABLED = !Config.OnlyPublicSchematics && !Config.test() && Config.TechhiderActive;
@ -165,7 +166,7 @@ public class TechHider extends StateDependent {
BlockPosition pos = packet.getBlockPositionModifier().read(0);
Player p = e.getPlayer();
if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ())))
if(bypass(p, posToChunk(pos.getX()), posToChunk(pos.getZ())))
return;
PacketContainer cached = packetCache.get(packet);
@ -193,7 +194,7 @@ public class TechHider extends StateDependent {
BlockPosition pos = packet.getBlockPositionModifier().read(0);
Player p = e.getPlayer();
if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ())))
if(bypass(p, posToChunk(pos.getX()), posToChunk(pos.getZ())))
return;
e.setCancelled(true);
@ -207,7 +208,7 @@ public class TechHider extends StateDependent {
BlockPosition pos = packet.getBlockPositionModifier().read(0);
Player p = e.getPlayer();
if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ())))
if(bypass(p, posToChunk(pos.getX()), posToChunk(pos.getZ())))
return;
@ -236,7 +237,7 @@ public class TechHider extends StateDependent {
BlockPosition pos = packet.getBlockPositionModifier().read(0);
Player p = event.getPlayer();
if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ())))
if(bypass(p, posToChunk(pos.getX()), posToChunk(pos.getZ())))
return;
// 9 == Set sign text
@ -269,6 +270,73 @@ public class TechHider extends StateDependent {
}, 40);
}
static boolean bypass(Player p, int chunkX, int chunkZ){
if(p == FightSystem.getEventLeiter())
return true;
FightTeam ft = Fight.getPlayerTeam(p);
if(ft == null){
return Config.ArenaRegion.chunkOutside(chunkX, chunkZ);
}else if(ft.isBlue()){
return ft.canPlayerEntern(p) || Config.RedExtendRegion.chunkOutside(chunkX, chunkZ);
}else{
return ft.canPlayerEntern(p) || Config.BlueExtendRegion.chunkOutside(chunkX, chunkZ);
}
}
private static int posToChunk(int c){
int chunk = c / 16;
if(c<0)
chunk--;
return chunk;
}
static int readVarInt(byte[] array, int startPos) {
int numRead = 0;
int result = 0;
byte read;
do {
read = array[startPos + numRead];
int value = (read & 0b01111111);
result |= (value << (7 * numRead));
numRead++;
if (numRead > 5) {
break;
}
} while ((read & 0b10000000) != 0);
return result;
}
static int readVarIntLength(byte[] array, int startPos) {
int numRead = 0;
byte read;
do {
read = array[startPos + numRead];
numRead++;
if (numRead > 5) {
break;
}
} while ((read & 0b10000000) != 0);
return numRead;
}
static byte[] writeVarInt(int value) {
List<Byte> buffer = new ArrayList<>(5);
do {
byte temp = (byte)(value & 0b01111111);
// Note: >>> means that the sign bit is shifted with the rest of the number rather than being left alone
value >>>= 7;
if (value != 0) {
temp |= 0b10000000;
}
buffer.add(temp);
} while (value != 0);
return Bytes.toArray(buffer);
}
public static class ChunkPos{
final int x;
final int z;