From 4015b7eb95d35e8672a8069f82baf1fc2d270aeb Mon Sep 17 00:00:00 2001 From: Moresteck Date: Tue, 15 Oct 2024 11:17:17 +0000 Subject: [PATCH] Fix some debug messages logging in non-debug mode --- .../legacyfix/patch/PatchHelper.java | 21 ++++++++++++++----- .../legacyfix/patch/impl/MousePatch.java | 13 +++++++----- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/main/java/uk/betacraft/legacyfix/patch/PatchHelper.java b/src/main/java/uk/betacraft/legacyfix/patch/PatchHelper.java index 11f01dd..a671756 100644 --- a/src/main/java/uk/betacraft/legacyfix/patch/PatchHelper.java +++ b/src/main/java/uk/betacraft/legacyfix/patch/PatchHelper.java @@ -9,6 +9,7 @@ import javassist.NotFoundException; import javassist.bytecode.ConstPool; import uk.betacraft.legacyfix.LFLogger; +import uk.betacraft.legacyfix.LegacyFixAgent; public class PatchHelper { public static final CtClass stringClass = ClassPool.getDefault().getOrNull("java.lang.String"); @@ -59,7 +60,9 @@ public static CtClass findMinecraftClass(ClassPool pool) throws NotFoundExceptio !className.equals("long")) { minecraftClass = field.getType(); - LFLogger.info("Found Minecraft class: " + minecraftClass.getName()); + if (LegacyFixAgent.isDebug()) + LFLogger.info("Found Minecraft class: " + minecraftClass.getName()); + break; } } @@ -85,7 +88,9 @@ public static CtField findMinecraftField(ClassPool pool) throws NotFoundExceptio !className.equals("long")) { minecraftField = field; - LFLogger.info("Found Minecraft field: " + field.getName()); + if (LegacyFixAgent.isDebug()) + LFLogger.info("Found Minecraft field: " + field.getName()); + return field; } } @@ -108,7 +113,9 @@ public static CtField findAppletModeField(ClassPool pool) throws NotFoundExcepti if (className.equals("boolean") && Modifier.isPublic(field.getModifiers())) { appletModeField = field; - LFLogger.info("Found appletMode field: " + appletModeField.getName()); + if (LegacyFixAgent.isDebug()) + LFLogger.info("Found appletMode field: " + appletModeField.getName()); + break; } } @@ -132,10 +139,14 @@ public static CtClass findMouseHelperClass(ClassPool pool) throws NotFoundExcept for (CtConstructor constr : constructors) { CtClass[] constrParams = constr.getParameterTypes(); - if (constrParams.length >= 1 && constrParams[0].getName().equals("java.awt.Component")) { + if (constrParams.length >= 1 && + constrParams[0].getName().equals("java.awt.Component") && + !field.getType().getName().equals(minecraftClass.getName())) { mouseHelperClass = field.getType(); - LFLogger.info("Found match for MouseHelper class: " + mouseHelperClass.getName()); + if (LegacyFixAgent.isDebug()) + LFLogger.info("Found match for MouseHelper class: " + mouseHelperClass.getName()); + break; } } diff --git a/src/main/java/uk/betacraft/legacyfix/patch/impl/MousePatch.java b/src/main/java/uk/betacraft/legacyfix/patch/impl/MousePatch.java index 96be35a..9fbb46d 100644 --- a/src/main/java/uk/betacraft/legacyfix/patch/impl/MousePatch.java +++ b/src/main/java/uk/betacraft/legacyfix/patch/impl/MousePatch.java @@ -65,7 +65,8 @@ public void apply(final Instrumentation inst) throws Exception { // Mouse handling changed sometime during alpha boolean invert = "invert".equals(LegacyFixAgent.getSetting("lf.mouse", "no")); - LFLogger.info("MOUSE Y INVERT: " + invert); + if (LegacyFixAgent.isDebug()) + LFLogger.info("mouse", "Mouse Y invert: " + invert); if (mouseHelperMethods.length == 2) { mouseHelperMethods[1].setBody((invert ? body2invert : body2)); @@ -87,7 +88,7 @@ public void apply(final Instrumentation inst) throws Exception { inst.addTransformer(new ClassFileTransformer() { public byte[] transform(ClassLoader loader, String className, Class classRedefined, ProtectionDomain domain, byte[] classfileBuffer) { CtClass clas = pool.getOrNull(className.replace("/", ".")); - if (clas == null || clas.getName().startsWith("org.lwjgl") || clas.getName().equals(mouseHelperClass.getName())) { + if (clas == null || clas.getName().startsWith("org.lwjgl") || clas.getName().equals(mouseHelperClass.getName()) || clas.isFrozen()) { return null; } @@ -99,14 +100,16 @@ public void edit(MethodCall m) throws CannotCompileException { "()I".equalsIgnoreCase(m.getSignature())) { mouseDXYmatched = true; m.replace("$_ = 0;"); - LFLogger.info("Mouse.getDX() match!"); + if (LegacyFixAgent.isDebug()) + LFLogger.info("mouse", "Mouse.getDX() match!"); } else if ("org.lwjgl.input.Mouse".equals(m.getClassName()) && "getDY".equals(m.getMethodName()) && "()I".equalsIgnoreCase(m.getSignature())) { mouseDXYmatched = true; m.replace("$_ = 0;"); - LFLogger.info("Mouse.getDY() match!"); + if (LegacyFixAgent.isDebug()) + LFLogger.info("mouse", "Mouse.getDY() match!"); } } }); @@ -118,7 +121,7 @@ public void edit(MethodCall m) throws CannotCompileException { return clas.toBytecode(); } } catch (Throwable t) { - LFLogger.error(t.toString()); + LFLogger.error("mouse", t); } return null;