From 3fdb34245d52cc4f8cfc7a226cd5da1e34eac22f Mon Sep 17 00:00:00 2001 From: Chicken-Bones Date: Wed, 27 Aug 2014 14:27:19 +1000 Subject: [PATCH] Fixed lag when getting game profiles Fixed runtime deobf Cleaned a few imports --- build/build.properties | 2 +- src/codechicken/core/GuiModListScroll.java | 37 +++++++++++++++++- src/codechicken/core/ServerUtils.java | 38 +++++++++++++++++-- .../core/asm/MCPDeobfuscationTransformer.java | 17 ++------- 4 files changed, 73 insertions(+), 21 deletions(-) diff --git a/build/build.properties b/build/build.properties index f161d63..0482921 100644 --- a/build/build.properties +++ b/build/build.properties @@ -1,4 +1,4 @@ mc_version=1.7.10 forge_version=10.13.0.1151 -ccl_version=1.1.1.98 +ccl_version=1.1.1.99 mod_version=1.0.3 diff --git a/src/codechicken/core/GuiModListScroll.java b/src/codechicken/core/GuiModListScroll.java index 063c3f5..8375fcf 100644 --- a/src/codechicken/core/GuiModListScroll.java +++ b/src/codechicken/core/GuiModListScroll.java @@ -9,11 +9,20 @@ import cpw.mods.fml.common.ModContainer; import cpw.mods.fml.common.ModMetadata; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.MinecraftForgeClient; +import org.lwjgl.BufferUtils; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; -import static org.lwjgl.opengl.GL11.*; +import javax.imageio.ImageIO; +import static org.lwjgl.opengl.GL11.*; +import static org.lwjgl.opengl.GL11.glReadPixels; + +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.nio.ByteBuffer; import java.util.LinkedList; import java.util.List; @@ -32,6 +41,24 @@ public class GuiModListScroll scrollMods.add(mod); } + private static void screenshotStencil(int x) { + Dimension d = GuiDraw.displayRes(); + ByteBuffer buf = BufferUtils.createByteBuffer(d.width * d.height); + BufferedImage img = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB); + + glPixelStorei(GL_PACK_ALIGNMENT, 1); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glReadPixels(0, 0, d.width, d.height, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, buf); + for(int i = 0; i < d.width; i++) + for(int j = 0; j < d.height; j++) + img.setRGB(i, d.height-j-1, buf.get(j * d.width + i) == 0 ? 0 : 0xFFFFFF); + try { + ImageIO.write(img, "png", new File("stencil"+x+".png")); + } catch (IOException e) { + e.printStackTrace(); + } + } + private static ModContainer lastMod; private static double scroll; private static double lastFrameTime; @@ -60,11 +87,15 @@ public class GuiModListScroll glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO); GuiDraw.drawRect(0, 0, gui.width, gui.height, -1);//clear stencil buffer + screenshotStencil(1); + glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); - GuiDraw.drawRect(x1, y1, gui.width-x1, gui.height-y1, -1);//add description area (even below button) + GuiDraw.drawRect(x1, y1, gui.width - x1, gui.height - y1, -1);//add description area (even below button) glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO); GuiDraw.drawRect(gui.width / 2 - 75, y2, 200, 20, -1);//subtract done button + screenshotStencil(2); + glColorMask(true, true, true, true); glStencilFunc(GL_EQUAL, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); @@ -77,6 +108,8 @@ public class GuiModListScroll glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); GuiDraw.drawRect(x1, y1draw, x2-x1, y2-y1draw, -1); + screenshotStencil(3); + glColorMask(true, true, true, true); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); diff --git a/src/codechicken/core/ServerUtils.java b/src/codechicken/core/ServerUtils.java index 5a46548..10e6888 100644 --- a/src/codechicken/core/ServerUtils.java +++ b/src/codechicken/core/ServerUtils.java @@ -1,15 +1,18 @@ package codechicken.core; +import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; +import java.util.Locale; +import java.util.Map; +import codechicken.lib.asm.ObfMapping; import com.mojang.authlib.GameProfile; import net.minecraft.server.MinecraftServer; -import net.minecraft.command.CommandHandler; import net.minecraft.inventory.Container; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.command.ICommand; import net.minecraft.util.IChatComponent; public class ServerUtils extends CommonUtils @@ -44,14 +47,41 @@ public class ServerUtils extends CommonUtils player.openContainer.addCraftingToCrafters(player); } + private static Field field_152661_c; + private static Class c_ProfileEntry; + private static Method func_152668_a; + static { + try { + field_152661_c = ReflectionManager.getField(new ObfMapping("net/minecraft/server/management/PlayerProfileCache", "field_152661_c", "[Ljava/util/Map;")); + c_ProfileEntry = ServerUtils.class.getClassLoader().loadClass("net.minecraft.server.management.PlayerProfileCache$ProfileEntry"); + func_152668_a = c_ProfileEntry.getDeclaredMethod( + new ObfMapping("net/minecraft/server/management/PlayerProfileCache$ProfileEntry", + "func_152668_a", "()Lcom/mojang/authlib/GameProfile;").toRuntime().s_name); + func_152668_a.setAccessible(true); + + } catch (Exception e) { + throw new RuntimeException(e); + } + } public static GameProfile getGameProfile(String username) { + EntityPlayer player = getPlayer(username); + if(player != null) + return player.getGameProfile(); + + username = username.toLowerCase(Locale.ROOT); + try {//use reflection to bypass saving the game profiles every time we ask the cache for one + Object cacheEntry = ((Map) field_152661_c.get(mc().func_152358_ax())).get(username); + if(cacheEntry != null) + return (GameProfile) func_152668_a.invoke(cacheEntry); + } catch (Exception e) { + throw new RuntimeException(e); + } return mc().func_152358_ax().func_152655_a(username); } public static boolean isPlayerOP(String username) { GameProfile prof = getGameProfile(username); - if(prof == null) return false; - return mc().getConfigurationManager().func_152596_g(getGameProfile(username)); + return prof != null && mc().getConfigurationManager().func_152596_g(prof); } public static boolean isPlayerOwner(String username) { diff --git a/src/codechicken/core/asm/MCPDeobfuscationTransformer.java b/src/codechicken/core/asm/MCPDeobfuscationTransformer.java index fa65e57..a296fe7 100644 --- a/src/codechicken/core/asm/MCPDeobfuscationTransformer.java +++ b/src/codechicken/core/asm/MCPDeobfuscationTransformer.java @@ -1,6 +1,5 @@ package codechicken.core.asm; -import java.io.File; import java.io.IOException; import java.lang.reflect.Field; import java.util.*; @@ -19,16 +18,13 @@ import org.objectweb.asm.tree.MethodNode; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; -import codechicken.core.launch.CodeChickenCorePlugin; import codechicken.lib.asm.ASMHelper; import codechicken.lib.asm.CC_ClassWriter; import codechicken.lib.asm.ObfMapping; -import codechicken.lib.config.ConfigFile; import codechicken.obfuscator.IHeirachyEvaluator; import codechicken.obfuscator.ObfuscationRun; import codechicken.obfuscator.ObfuscationMap.ObfuscationEntry; import cpw.mods.fml.common.asm.transformers.AccessTransformer; -import cpw.mods.fml.common.asm.transformers.DeobfuscationTransformer; import net.minecraft.launchwrapper.IClassTransformer; import net.minecraft.launchwrapper.LaunchClassLoader; @@ -118,18 +114,15 @@ public class MCPDeobfuscationTransformer implements IClassTransformer, Opcodes, public static void load() { CodeChickenCoreModContainer.loadConfig(); - ConfigFile config = CodeChickenCoreModContainer.config; - File mcDir = CodeChickenCorePlugin.minecraftDir; - if (config.getTag("dev.deobfuscate") + if (CodeChickenCoreModContainer.config.getTag("dev.deobfuscate") .setComment("set to true to completely deobfuscate mcp names") .getBooleanValue(!ObfMapping.obfuscated)) { run = new ObfuscationRun(false, ObfMapping.MCPRemapper.getConfFiles(), ObfuscationRun.fillDefaults(new HashMap())); run.obf.setHeirachyEvaluator(instance); run.setQuiet().parseMappings(); - for (String pkg : run.config.get("excludedPackages").split(";")) - excludedPackages.add(pkg); + Collections.addAll(excludedPackages, run.config.get("excludedPackages").split(";")); if (ObfMapping.obfuscated) { ObfMapping.loadMCPRemapper(); @@ -168,11 +161,7 @@ public class MCPDeobfuscationTransformer implements IClassTransformer, Opcodes, if (ObfMapping.obfuscated) { //move ourselves to the end List transformers = getTransformers(); - for (Iterator iterator = transformers.iterator(); iterator.hasNext(); ) { - IClassTransformer t = iterator.next(); - if (t == instance || t instanceof DeobfuscationTransformer) - iterator.remove(); - } + transformers.remove(instance); transformers.add(instance); } else { //remap access transformers