Skip to content

Commit

Permalink
Fix some debug messages logging in non-debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Moresteck committed Oct 15, 2024
1 parent 6a689e4 commit 4015b7e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
21 changes: 16 additions & 5 deletions src/main/java/uk/betacraft/legacyfix/patch/PatchHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/uk/betacraft/legacyfix/patch/impl/MousePatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;
}

Expand All @@ -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!");
}
}
});
Expand All @@ -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;
Expand Down

0 comments on commit 4015b7e

Please sign in to comment.