3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-08 17:20:24 +01:00

Fix anti-xray for 1.9 (#393)

* Fix anti-xray for 1.9

* Bye NMS.

* Perform

* Add config option
Dieser Commit ist enthalten in:
Mats 2016-05-10 20:53:37 +02:00 committet von Myles
Ursprung ac6e8b1709
Commit 82bf11fcbc
5 geänderte Dateien mit 42 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -442,6 +442,11 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI, ViaVe
return getConfig().getString("tracking-max-kick-msg", "You are sending too many packets, :("); return getConfig().getString("tracking-max-kick-msg", "You are sending too many packets, :(");
} }
@Override
public boolean isAntiXRay() {
return getConfig().getBoolean("anti-xray-patch", true);
}
public boolean isAutoTeam() { public boolean isAutoTeam() {
// Collision has to be enabled first // Collision has to be enabled first
return isPreventCollision() && getConfig().getBoolean("auto-team", true); return isPreventCollision() && getConfig().getBoolean("auto-team", true);

Datei anzeigen

@ -142,4 +142,11 @@ public interface ViaVersionConfig {
* @return Kick message, with colour codes using '&' * @return Kick message, with colour codes using '&'
*/ */
String getMaxWarningsKickMessage(); String getMaxWarningsKickMessage();
/**
* Is anti-xray enabled?
*
* @return A boolean
*/
boolean isAntiXRay();
} }

Datei anzeigen

@ -4,10 +4,12 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.util.ReflectionUtil; import us.myles.ViaVersion.util.ReflectionUtil;
import java.lang.reflect.Method;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
@ -17,11 +19,15 @@ public class ClientChunks extends StoredObject {
// Reflection // Reflection
private static ReflectionUtil.ClassReflection mapChunkBulkRef; private static ReflectionUtil.ClassReflection mapChunkBulkRef;
private static ReflectionUtil.ClassReflection mapChunkRef; private static ReflectionUtil.ClassReflection mapChunkRef;
private static Method obfuscateRef;
private static Class<?> worldRef;
static { static {
try { try {
mapChunkBulkRef = new ReflectionUtil.ClassReflection(ReflectionUtil.nms("PacketPlayOutMapChunkBulk")); mapChunkBulkRef = new ReflectionUtil.ClassReflection(ReflectionUtil.nms("PacketPlayOutMapChunkBulk"));
mapChunkRef = new ReflectionUtil.ClassReflection(ReflectionUtil.nms("PacketPlayOutMapChunk")); mapChunkRef = new ReflectionUtil.ClassReflection(ReflectionUtil.nms("PacketPlayOutMapChunk"));
obfuscateRef = Class.forName("org.spigotmc.AntiXray").getMethod("obfuscate", int.class, int.class, int.class, byte[].class, ReflectionUtil.nms("World"));
worldRef = ReflectionUtil.nms("World");
} catch (Exception e) { } catch (Exception e) {
Bukkit.getLogger().log(Level.WARNING, "Failed to initialise chunk reflection", e); Bukkit.getLogger().log(Level.WARNING, "Failed to initialise chunk reflection", e);
} }
@ -44,6 +50,20 @@ public class ClientChunks extends StoredObject {
int[] xcoords = mapChunkBulkRef.getFieldValue("a", packet, int[].class); int[] xcoords = mapChunkBulkRef.getFieldValue("a", packet, int[].class);
int[] zcoords = mapChunkBulkRef.getFieldValue("b", packet, int[].class); int[] zcoords = mapChunkBulkRef.getFieldValue("b", packet, int[].class);
Object[] chunkMaps = mapChunkBulkRef.getFieldValue("c", packet, Object[].class); Object[] chunkMaps = mapChunkBulkRef.getFieldValue("c", packet, Object[].class);
if (ViaVersion.getConfig().isAntiXRay()) { //Spigot anti-xray patch
Object world = mapChunkBulkRef.getFieldValue("world", packet, Object.class);
for (int i = 0; i < xcoords.length; ++i) {
Object spigotConfig = ReflectionUtil.getPublic(world, "spigotConfig", Object.class);
Object antiXrayInstance = ReflectionUtil.getPublic(spigotConfig, "antiXrayInstance", Object.class);
Object b = ReflectionUtil.get(chunkMaps[i], "b", Object.class);
Object a = ReflectionUtil.get(chunkMaps[i], "a", Object.class);
obfuscateRef.invoke(antiXrayInstance, xcoords[i], zcoords[i], b, a, world);
}
}
for (int i = 0; i < chunkMaps.length; i++) { for (int i = 0; i < chunkMaps.length; i++) {
int x = xcoords[i]; int x = xcoords[i];
int z = zcoords[i]; int z = zcoords[i];

Datei anzeigen

@ -60,6 +60,13 @@ public class ReflectionUtil {
return (T) field.get(o); return (T) field.get(o);
} }
public static <T> T getPublic(Object o, String f, Class<T> t) throws NoSuchFieldException, IllegalAccessException {
Field field = o.getClass().getField(f);
field.setAccessible(true);
return (T) field.get(o);
}
public static void set(Object o, String f, Object value) throws NoSuchFieldException, IllegalAccessException { public static void set(Object o, String f, Object value) throws NoSuchFieldException, IllegalAccessException {
Field field = o.getClass().getDeclaredField(f); Field field = o.getClass().getDeclaredField(f);
field.setAccessible(true); field.setAccessible(true);

Datei anzeigen

@ -52,3 +52,5 @@ tracking-warning-pps: 120
# This can never be higher than "tracking-interval" # This can never be higher than "tracking-interval"
tracking-max-warnings: 4 tracking-max-warnings: 4
tracking-max-kick-msg: "You are sending too many packets, :(" tracking-max-kick-msg: "You are sending too many packets, :("
# Patch the Anti xray to work on 1.9 (If your server is 1.8) This can cost more performance, so disable it if you don't use it.
anti-xray-patch: true