Skip to content

Commit

Permalink
more robust optifine detection
Browse files Browse the repository at this point in the history
  • Loading branch information
FalsePattern committed Aug 12, 2024
1 parent b80d5fc commit 3ce925c
Showing 1 changed file with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.TypeInsnNode;

import net.minecraft.launchwrapper.Launch;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.relauncher.FMLLaunchHandler;
import cpw.mods.fml.relauncher.Side;

/**
Expand Down Expand Up @@ -69,11 +72,36 @@ public boolean shouldTransformClass(@NotNull String className, @NotNull ClassNod
}

private static class LazyOptiFineCheck {
private static Boolean optifineDetected = null;
private static boolean hasOptiFine() {
if (FMLCommonHandler.instance().getSide() == Side.CLIENT) {
return FMLClientHandler.instance().hasOptifine();
Boolean detected = optifineDetected;
if (detected == null) {
if (FMLLaunchHandler.side().isClient()) {
try {
//We might be too early but let's try the standard way
detected = FMLClientHandler.instance().hasOptifine();
} catch (Throwable ignored) {
//Ok, we'll do it manually then
try {
ClassLoader cl;
cl = Loader.instance().getModClassLoader();
if (cl == null) {
cl = Launch.classLoader;
}
Class.forName("Config", false, cl);
detected = true;
} catch (Throwable ignored1) {
//99.9% sure that optifine is not present
detected = false;
}
}
} else {
//server shouldn't have OF
detected = false;
}
optifineDetected = detected;
}
return false;
return detected;
}
}

Expand Down

0 comments on commit 3ce925c

Please sign in to comment.