Skip to content

Commit

Permalink
Disable STB stitching if FC 1.23 is present even with OF
Browse files Browse the repository at this point in the history
  • Loading branch information
makamys committed Nov 29, 2023
1 parent ecdd15f commit 68a82c7
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/main/java/me/eigenraven/lwjgl3ify/core/Lwjgl3ifyCoremod.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package me.eigenraven.lwjgl3ify.core;

import java.awt.Toolkit;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;

import net.minecraft.launchwrapper.Launch;
import net.minecraft.launchwrapper.LaunchClassLoader;

import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -131,10 +134,13 @@ public List<String> getMixins(Set<String> loadedCoreMods) {
LOGGER.info("Disabling STB texture loading mixin");
}

final boolean fcBugTriggered = hasFastcraft && !hasOptifine;
final boolean fcBugFixedByOF = isFastcraftVersion1_25();
final boolean fcBugTriggered = hasFastcraft && !(hasOptifine && fcBugFixedByOF);
if (fcBugTriggered && !Config.MIXIN_STBI_IGNORE_FASTCRAFT) {
LOGGER.error(
"Not using STB stiching mixins because FastCraft is installed to prevent rapidly flashing screen. Remove FastCraft or add OptiFine to enable these performance-improving patches.");
"Not using STB stiching mixins because FastCraft is installed to prevent rapidly flashing screen. Remove FastCraft or "
+ (!fcBugFixedByOF ? "update to FastCraft 1.25 and " : "")
+ "add OptiFine to enable these performance-improving patches.");
} else {
if (Config.MIXIN_STBI_TEXTURE_STICHING) {
LOGGER.info("Enabling STB texture stitching mixin");
Expand All @@ -146,4 +152,24 @@ public List<String> getMixins(Set<String> loadedCoreMods) {
}
return mixins;
}

private static boolean isFastcraftVersion1_25() {
// FastCraft tweaker hasn't run yet so no easy way to grab version.
// Let's compare the hash of fastcraft.a, which contains the version string in both 1.23 and 1.25.
try {
byte[] bytes = Launch.classLoader.getClassBytes("fastcraft.a");

if (bytes == null) return false;

MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest(bytes);

final byte[] fc125AHash = new byte[] { -125, -16, 44, -79, -105, 108, -65, -19, 56, -98, -65, -94, 0, -49,
66, -58, -60, -39, -23, 55, 87, 127, -77, 100, 73, -92, 37, 84, 115, -114, -76, -23 };

return Arrays.equals(fc125AHash, hash);
} catch (Exception e) {
return false;
}
}
}

0 comments on commit 68a82c7

Please sign in to comment.