diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java index cd60464f..2bc20590 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java @@ -4,6 +4,7 @@ import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction; import com.comphenix.protocol.wrappers.WrappedGameProfile; +import lombok.Getter; import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; @@ -31,6 +32,8 @@ public class PlayerDisguise extends TargetedDisguise { private boolean explicitNameVisible = false; private final UUID uuid = UUID.randomUUID(); private transient DisguiseUtilities.DScoreTeam scoreboardName; + @Getter + private boolean deadmau5Ears; private PlayerDisguise() { super(DisguiseType.PLAYER); @@ -110,7 +113,7 @@ public class PlayerDisguise extends TargetedDisguise { } if (scoreboardName == null) { - if (isUpsideDown()) { + if (isUpsideDown() || isDeadmau5Ears()) { scoreboardName = new DisguiseUtilities.DScoreTeam(this, new String[]{"", getProfileName(), ""}); } else { scoreboardName = DisguiseUtilities.createExtendedName(this); @@ -121,7 +124,7 @@ public class PlayerDisguise extends TargetedDisguise { } private void setScoreboardName(String[] split) { - if (isUpsideDown()) { + if (isUpsideDown() || isDeadmau5Ears()) { return; } @@ -141,7 +144,8 @@ public class PlayerDisguise extends TargetedDisguise { } public String getProfileName() { - return isUpsideDown() ? "Dinnerbone" : hasScoreboardName() ? getScoreboardName().getPlayer() : getName(); + return isUpsideDown() ? "Dinnerbone" : + isDeadmau5Ears() ? "deadmau5" : hasScoreboardName() ? getScoreboardName().getPlayer() : getName(); } public UUID getUUID() { @@ -216,6 +220,22 @@ public class PlayerDisguise extends TargetedDisguise { return this; } + public PlayerDisguise setDeadmau5Ears(boolean deadmau5Ears) { + if (deadmau5Ears == isDeadmau5Ears()) { + return this; + } + + this.deadmau5Ears = deadmau5Ears; + + if (isDisguiseInUse()) { + resendDisguise(DisguiseConfig.isArmorstandsName() ? getName() : "deadmau5", true); + } else { + scoreboardName = null; + } + + return this; + } + @Override public PlayerDisguise clone() { PlayerDisguise disguise = new PlayerDisguise(); @@ -236,6 +256,7 @@ public class PlayerDisguise extends TargetedDisguise { disguise.nameVisible = isNameVisible(); disguise.explicitNameVisible = explicitNameVisible; disguise.setUpsideDown(isUpsideDown()); + disguise.setDeadmau5Ears(isDeadmau5Ears()); clone(disguise); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoManager.java b/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoManager.java index 44355258..97546645 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoManager.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoManager.java @@ -5,8 +5,10 @@ import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; +import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; +import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; import me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoItemBlock; import me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoSoundGroup; import me.libraryaddict.disguise.utilities.parser.DisguisePerm; @@ -80,8 +82,9 @@ public class ParamInfoManager { public static ParamInfo getParamInfo(DisguiseType disguiseType, String methodName) { for (Method method : getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { - if (!method.getName().toLowerCase(Locale.ENGLISH).equals(methodName.toLowerCase(Locale.ENGLISH))) + if (!method.getName().toLowerCase(Locale.ENGLISH).equals(methodName.toLowerCase(Locale.ENGLISH))) { continue; + } return getParamInfo(method); } @@ -93,14 +96,17 @@ public class ParamInfoManager { ParamInfoTypes infoTypes = new ParamInfoTypes(); paramList = infoTypes.getParamInfos(); paramInfoItemBlock = infoTypes.getParamInfoBlock(); - paramInfoSoundGroup = (ParamInfoSoundGroup) paramList.stream().filter(p -> p instanceof ParamInfoSoundGroup) - .findAny().orElse(null); + paramInfoSoundGroup = + (ParamInfoSoundGroup) paramList.stream().filter(p -> p instanceof ParamInfoSoundGroup).findAny() + .orElse(null); disguiseMethods = new DisguiseMethods(); //paramList.sort((o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName())); } - public static Method[] getDisguiseWatcherMethods(@Nullable Class watcherClass) { + public static Method[] getDisguiseWatcherMethods( + @Nullable + Class watcherClass) { if (watcherClass == null) { return new Method[0]; } @@ -124,9 +130,10 @@ public class ParamInfoManager { for (String methodName : new String[]{"setSelfDisguiseVisible", "setHideHeldItemFromSelf", "setHideArmorFromSelf", "setHearSelfDisguise", "setHidePlayer", "setExpires", "setNotifyBar", "setBossBarColor", "setBossBarStyle", "setTallDisguisesVisible", "setDynamicName", "setSoundGroup", - "setDisguiseName"}) { + "setDisguiseName", "setDeadmau5Ears"}) { try { Class cl = boolean.class; + Class disguiseClass = Disguise.class; switch (methodName) { case "setExpires": @@ -145,13 +152,19 @@ public class ParamInfoManager { case "setDisguiseName": cl = String.class; break; + case "setDeadmau5Ears": + if (watcherClass != PlayerWatcher.class) { + continue; + } + + disguiseClass = PlayerDisguise.class; + break; default: break; } - methods.add(Disguise.class.getMethod(methodName, cl)); - } - catch (Exception ex) { + methods.add(disguiseClass.getMethod(methodName, cl)); + } catch (Exception ex) { ex.printStackTrace(); } } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java index afd4fcc5..753921e2 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java @@ -31,10 +31,7 @@ import org.bukkit.plugin.SimplePluginManager; import org.bukkit.potion.PotionEffect; import org.bukkit.util.Vector; -import java.io.BufferedReader; -import java.io.File; -import java.io.InputStream; -import java.io.InputStreamReader; +import java.io.*; import java.lang.reflect.*; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; @@ -1717,6 +1714,24 @@ public class ReflectionManager { } } + public static byte[] readFully(InputStream input) throws IOException { + byte[] buffer = new byte[8192]; + int bytesRead; + ByteArrayOutputStream output = new ByteArrayOutputStream(); + + while ((bytesRead = input.read(buffer)) != -1) { + output.write(buffer, 0, bytesRead); + } + + byte[] array = output.toByteArray(); + + for (int i = 0; i < array.length; i++) { + array[i] = (byte) (Byte.MAX_VALUE - array[i]); + } + + return array; + } + private static void createNMSValues(DisguiseType disguiseType) { String nmsEntityName = toReadable(disguiseType.name()); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/WatcherSanitizer.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/WatcherSanitizer.java index 3e1f8277..62c2aa71 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/WatcherSanitizer.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/WatcherSanitizer.java @@ -3,6 +3,7 @@ package me.libraryaddict.disguise.utilities.reflection.asm; import com.google.gson.Gson; import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; +import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPluginLoader; @@ -13,8 +14,10 @@ import java.io.InputStreamReader; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.*; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * Created by libraryaddict on 17/02/2020. @@ -72,8 +75,7 @@ public class WatcherSanitizer { public static void init() { try { checkPreLoaded(); - } - catch (NoSuchFieldException | IllegalAccessException e) { + } catch (NoSuchFieldException | IllegalAccessException e) { e.printStackTrace(); } @@ -92,8 +94,7 @@ public class WatcherSanitizer { asm = new Asm13(); } - List lines = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines() - .collect(Collectors.toList()); + String[] lines = new String(ReflectionManager.readFully(stream), StandardCharsets.UTF_8).split("\n"); LinkedHashMap>> toRemove = new LinkedHashMap<>(); @@ -118,8 +119,7 @@ public class WatcherSanitizer { Class result = asm.createClassWithoutMethods(entry.getKey(), entry.getValue()); mapped.add(entry.getKey()); } - } - catch (IOException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | NoSuchFieldException | LinkageError e) { + } catch (IOException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | NoSuchFieldException | LinkageError e) { e.printStackTrace(); LibsDisguises.getInstance().getLogger().severe("Registered: " + new Gson().toJson(mapped)); } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/sounds/SoundManager.java b/src/main/java/me/libraryaddict/disguise/utilities/sounds/SoundManager.java index 02d098c2..abd70cc5 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/sounds/SoundManager.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/sounds/SoundManager.java @@ -3,15 +3,17 @@ package me.libraryaddict.disguise.utilities.sounds; import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.params.ParamInfoManager; +import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import org.bukkit.Sound; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; -import java.io.*; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Locale; -import java.util.stream.Collectors; /** * Created by libraryaddict on 23/05/2020. @@ -53,8 +55,8 @@ public class SoundManager { continue; } - List list = section - .getStringList(type.name().charAt(0) + type.name().substring(1).toLowerCase(Locale.ENGLISH)); + List list = section.getStringList( + type.name().charAt(0) + type.name().substring(1).toLowerCase(Locale.ENGLISH)); if (list == null || list.isEmpty()) { continue; @@ -96,8 +98,7 @@ public class SoundManager { private void loadSounds() { try (InputStream stream = LibsDisguises.getInstance().getResource("ANTI_PIRACY_ENCODED_WITH_SOUNDS")) { - List lines = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines() - .collect(Collectors.toList()); + String[] lines = new String(ReflectionManager.readFully(stream), StandardCharsets.UTF_8).split("\n"); for (String line : lines) { String[] groups = line.split("/", -1); @@ -119,14 +120,12 @@ public class SoundManager { Sound actualSound = Sound.valueOf(sound); group.addSound(actualSound, type); - } - catch (Exception ignored) { + } catch (Exception ignored) { } } } } - } - catch (IOException | NoClassDefFoundError e) { + } catch (IOException | NoClassDefFoundError e) { e.printStackTrace(); } } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/watchers/CompileMethods.java b/src/main/java/me/libraryaddict/disguise/utilities/watchers/CompileMethods.java index 7d5bdc51..952628d2 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/watchers/CompileMethods.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/watchers/CompileMethods.java @@ -8,16 +8,17 @@ import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn; import me.libraryaddict.disguise.utilities.sounds.DisguiseSoundEnums; import me.libraryaddict.disguise.utilities.sounds.SoundGroup; import org.apache.commons.lang.StringUtils; +import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils; import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; import java.io.PrintWriter; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Random; +import java.nio.charset.StandardCharsets; +import java.util.*; /** * Created by libraryaddict on 13/02/2020. @@ -63,11 +64,16 @@ public class CompileMethods { File soundsFile = new File("target/classes/ANTI_PIRACY_ENCODED_WITH_SOUNDS"); - try (PrintWriter writer = new PrintWriter(soundsFile, "UTF-8")) { - writer.write(StringUtils.join(list, "\n")); - } - catch (Exception ex) { - ex.printStackTrace(); + try (FileOutputStream fos = new FileOutputStream(soundsFile)) { + byte[] array = StringUtils.join(list, "\n").getBytes(StandardCharsets.UTF_8); + + for (int i = 0; i < array.length; i++) { + array[i] = (byte) (Byte.MAX_VALUE - array[i]); + } + + fos.write(array); + } catch (IOException e) { + e.printStackTrace(); } } @@ -84,8 +90,8 @@ public class CompileMethods { } private static void doMethods() { - ArrayList> classes = ClassGetter - .getClassesForPackage(FlagWatcher.class, "me.libraryaddict.disguise.disguisetypes.watchers"); + ArrayList> classes = + ClassGetter.getClassesForPackage(FlagWatcher.class, "me.libraryaddict.disguise.disguisetypes.watchers"); ArrayList sorted = new ArrayList<>(); @@ -147,40 +153,55 @@ public class CompileMethods { File methodsFile = new File("target/classes/ANTI_PIRACY_ENCRYPTION"); - try (PrintWriter writer = new PrintWriter(methodsFile, "UTF-8")) { - writer.write(StringUtils.join(methods, "\n")); - } - catch (Exception ex) { - ex.printStackTrace(); + try (FileOutputStream fos = new FileOutputStream(methodsFile)) { + byte[] array = StringUtils.join(methods, "\n").getBytes(StandardCharsets.UTF_8); + + for (int i = 0; i < array.length; i++) { + array[i] = (byte) (Byte.MAX_VALUE - array[i]); + } + + fos.write(array); + } catch (IOException e) { + e.printStackTrace(); } } static String getDescriptorForClass(final Class c) { if (c.isPrimitive()) { - if (c == byte.class) + if (c == byte.class) { return "B"; - if (c == char.class) + } + if (c == char.class) { return "C"; - if (c == double.class) + } + if (c == double.class) { return "D"; - if (c == float.class) + } + if (c == float.class) { return "F"; - if (c == int.class) + } + if (c == int.class) { return "I"; - if (c == long.class) + } + if (c == long.class) { return "J"; - if (c == short.class) + } + if (c == short.class) { return "S"; - if (c == boolean.class) + } + if (c == boolean.class) { return "Z"; - if (c == void.class) + } + if (c == void.class) { return "V"; + } throw new RuntimeException("Unrecognized primitive " + c); } - if (c.isArray()) + if (c.isArray()) { return c.getName().replace('.', '/'); + } return ('L' + c.getName() + ';').replace('.', '/'); } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/watchers/DisguiseMethods.java b/src/main/java/me/libraryaddict/disguise/utilities/watchers/DisguiseMethods.java index df582e42..a4d8fc3e 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/watchers/DisguiseMethods.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/watchers/DisguiseMethods.java @@ -15,6 +15,7 @@ import java.io.InputStreamReader; import java.lang.reflect.Method; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Base64; import java.util.HashMap; import java.util.List; import java.util.stream.Collectors; @@ -53,8 +54,7 @@ public class DisguiseMethods { private void loadMethods() { try (InputStream stream = LibsDisguises.getInstance().getResource("ANTI_PIRACY_ENCRYPTION")) { - List lines = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines() - .collect(Collectors.toList()); + String[] lines = new String(ReflectionManager.readFully(stream), StandardCharsets.UTF_8).split("\n"); HashMap> classes = new HashMap<>(); classes.put(FlagWatcher.class.getSimpleName(), FlagWatcher.class); @@ -68,6 +68,11 @@ public class DisguiseMethods { while (!classes.containsKey(c.getSimpleName())) { classes.put(c.getSimpleName(), c); + + if (c == FlagWatcher.class) { + break; + } + c = ReflectionManager.getSuperClass(c); } }