Skip to content

Commit

Permalink
Remove annoying GL error message from Optifine/Shadersmod (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
Caedis authored Nov 15, 2023
1 parent e63656d commit 08e989c
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/main/java/com/mitchej123/hodgepodge/LoadingConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public class LoadingConfig {
public boolean preventPickupLoot;
public boolean removeSpawningMinecartSound;
public boolean removeCreativeSearchTab;
public boolean removeOptifineGLErrors;

public boolean compactChat;
public boolean dontInvertCrosshairColor;
Expand Down Expand Up @@ -326,6 +327,7 @@ public LoadingConfig(File file) {
enableMacosCmdShortcuts = config.get(Category.TWEAKS.toString(), "enableMacosCmdShortcuts", true, "Use CMD key on MacOS to COPY / INSERT / SELECT in text fields (Chat, NEI, Server IP etc.)").getBoolean();
removeSpawningMinecartSound = config.get(Category.TWEAKS.toString(), "removeSpawningMinecartSound", true, "Stop playing a sound when spawning a minecart in the world").getBoolean();
removeCreativeSearchTab = config.get(Category.FIXES.toString(), "removeCreativeSearchTab", true, "Disable the creative search tab since it can be very laggy in large modpacks").getBoolean();
removeOptifineGLErrors = config.get(Category.TWEAKS.toString(), "removeOptifineGLErrors", true, "Removes the 'GL error' message that appears when using a shader in Optifine/Shadersmod").getBoolean();
removeUpdateChecks = config.get(Category.FIXES.toString(), "removeUpdateChecks", true, "Remove old/stale/outdated update checks.").getBoolean();
chunkSaveCMEDebug = config.get(Category.DEBUG.toString(), "chunkSaveCMEDebug", false, "Enable chunk save cme debugging code.").getBoolean();
renderDebug = config.get(Category.DEBUG.toString(), "renderDebug", true, "Enable GL state debug hooks. Will not do anything useful unless mode is changed to nonzero.").getBoolean();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ public enum AsmTransformers {
"Take a sledgehammer to CraftServer.resetRecipes() to prevent it from breaking our Furnace Fix",
() -> Common.thermosTainted && Common.config.speedupVanillaFurnace,
Side.BOTH,
"com.mitchej123.hodgepodge.asm.transformers.thermos.ThermosFurnaceSledgeHammer");
"com.mitchej123.hodgepodge.asm.transformers.thermos.ThermosFurnaceSledgeHammer"),
OPTIFINE_REMOVE_GLERROR_LOGGING(
"Removes the logging of GL errors from OptiFine/Shadersmod",
() -> Common.config.removeOptifineGLErrors,
Side.CLIENT,
"com.mitchej123.hodgepodge.asm.transformers.optifine.GLErrorLoggingTransformer");
// spotless:on

private final Supplier<Boolean> applyIf;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.mitchej123.hodgepodge.asm.transformers.optifine;

import java.util.Iterator;

import net.minecraft.launchwrapper.IClassTransformer;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.LabelNode;
import org.objectweb.asm.tree.LocalVariableNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;

public class GLErrorLoggingTransformer implements IClassTransformer, Opcodes {

@Override
public byte[] transform(String name, String transformedName, byte[] basicClass) {
if ("shadersmod.client.Shaders".equals(transformedName)) {
final Logger logger = LogManager.getLogger("GLErrorLogging");
logger.debug("TRANSFORMING shadersmod.client.Shaders");
final ClassReader cr = new ClassReader(basicClass);
final ClassNode cn = new ClassNode();
cr.accept(cn, 0);
label: for (MethodNode mn : cn.methods) {
if (mn.name.equals("checkGLError")) {
final int maxlocals;
switch (mn.desc) {
case "(Ljava/lang/String;)I":
maxlocals = 1;
break;
case "(Ljava/lang/String;Ljava/lang/String;)I":
maxlocals = 2;
break;
case "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I":
maxlocals = 3;
break;
default:
break label;
}
logger.debug("Removing GL Error Logging: " + mn.desc);
mn.visitMaxs(1, maxlocals);
final InsnList list = mn.instructions;
list.clear();
LabelNode l0 = new LabelNode();
LabelNode l1 = new LabelNode();
list.add(l0);
list.add(new MethodInsnNode(INVOKESTATIC, "org/lwjgl/opengl/GL11", "glGetError", "()I", false));
list.add(new InsnNode(IRETURN));
list.add(l1);
final Iterator<LocalVariableNode> it = mn.localVariables.iterator();
while (it.hasNext()) {
final LocalVariableNode lv = it.next();
if (lv.desc.equals("Ljava/lang/String;")) {
lv.start = l0;
lv.end = l1;
} else {
it.remove();
}
}
}
}
final ClassWriter cw = new ClassWriter(0);
cn.accept(cw);
return cw.toByteArray();
}

return basicClass;
}
}

0 comments on commit 08e989c

Please sign in to comment.