From a1182865c4de1f76b5a943bb68f4a65eb6abada1 Mon Sep 17 00:00:00 2001 From: Jason Mitchell Date: Sat, 16 Nov 2024 11:15:52 -0800 Subject: [PATCH] Handle more incompatible mods * Removes reparsable coremod so they don't get injected as a mod later * Removes any registered mixin configs --- .../loading/MixinCompatHackTweaker.java | 89 ++++++++++++++++--- 1 file changed, 75 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/gtnewhorizons/angelica/loading/MixinCompatHackTweaker.java b/src/main/java/com/gtnewhorizons/angelica/loading/MixinCompatHackTweaker.java index 11f6a42a7..eacb964fb 100644 --- a/src/main/java/com/gtnewhorizons/angelica/loading/MixinCompatHackTweaker.java +++ b/src/main/java/com/gtnewhorizons/angelica/loading/MixinCompatHackTweaker.java @@ -4,15 +4,24 @@ import com.gtnewhorizons.angelica.transform.BlockTransformer; import com.gtnewhorizons.angelica.transform.RedirectorTransformer; import cpw.mods.fml.common.Loader; +import cpw.mods.fml.relauncher.CoreModManager; import cpw.mods.fml.relauncher.FMLLaunchHandler; import net.minecraft.launchwrapper.IClassTransformer; import net.minecraft.launchwrapper.ITweaker; import net.minecraft.launchwrapper.Launch; import net.minecraft.launchwrapper.LaunchClassLoader; +import org.spongepowered.asm.launch.platform.MixinContainer; +import org.spongepowered.asm.launch.platform.MixinPlatformManager; +import org.spongepowered.asm.launch.platform.container.IContainerHandle; +import org.spongepowered.asm.mixin.transformer.Config; import java.io.File; import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Map; +import java.util.Set; import static com.gtnewhorizons.angelica.loading.AngelicaTweaker.LOGGER; @@ -23,8 +32,8 @@ public void acceptOptions(List args, File gameDir, File assetsDir, Strin verifyDependencies(); if(DISABLE_OPTIFINE_FASTCRAFT_BETTERFPS) { - LOGGER.info("Disabling Optifine, Fastcraft, and BetterFPS (if present)"); - disableOptifineFastcraftAndBetterFPS(); + LOGGER.info("Disabling Optifine, Fastcraft, BetterFPS, and other incompatible mods (if present)"); + disableIncompatibleMods(); } if (AngelicaConfig.enableHudCaching){ @@ -40,8 +49,8 @@ private void verifyDependencies() { private void disableXaerosMinimapWaypointTransformer(){ try { - LaunchClassLoader lcl = Launch.classLoader; - Field xformersField = lcl.getClass().getDeclaredField("transformers"); + final LaunchClassLoader lcl = Launch.classLoader; + final Field xformersField = lcl.getClass().getDeclaredField("transformers"); xformersField.setAccessible(true); @SuppressWarnings("unchecked") List xformers = (List) xformersField.get(lcl); @@ -57,14 +66,14 @@ private void disableXaerosMinimapWaypointTransformer(){ } } - private void disableOptifineFastcraftAndBetterFPS() { - // Remove Optifine, Fastcraft, and BetterFPS transformers & Mod Containers + @SuppressWarnings("unchecked") + private void disableIncompatibleMods() { + // Remove transformers, Mod Containers, and mixins for Optifine, Fastcraft, BetterFPS and other incompatible mods try { - LaunchClassLoader lcl = Launch.classLoader; - Field xformersField = lcl.getClass().getDeclaredField("transformers"); + final LaunchClassLoader lcl = Launch.classLoader; + final Field xformersField = lcl.getClass().getDeclaredField("transformers"); xformersField.setAccessible(true); - @SuppressWarnings("unchecked") - List xformers = (List) xformersField.get(lcl); + final List xformers = (List) xformersField.get(lcl); for (int idx = xformers.size() - 1; idx >= 0; idx--) { final String name = xformers.get(idx).getClass().getName(); if (name.startsWith("optifine") || name.startsWith("fastcraft") || name.startsWith("me.guichaguri.betterfps")) { @@ -76,17 +85,69 @@ private void disableOptifineFastcraftAndBetterFPS() { throw new RuntimeException(e); } try { - Field injectedContainersField = Loader.class.getDeclaredField("injectedContainers"); + final Field injectedContainersField = Loader.class.getDeclaredField("injectedContainers"); injectedContainersField.setAccessible(true); - @SuppressWarnings("unchecked") - List containers = (List ) injectedContainersField.get(Loader.class); + final List containers = (List ) injectedContainersField.get(Loader.class); for (int idx = containers.size() - 1; idx >= 0; idx--) { - final String name = containers.get(idx); + final String name = containers.get(idx); if (name.startsWith("optifine") || name.startsWith("fastcraft")) { LOGGER.info("Removing mod container " + name); containers.remove(idx); } } + + final Field reparsedCoremodsField = CoreModManager.class.getDeclaredField("reparsedCoremods"); + final Field loadedCoremodsField = CoreModManager.class.getDeclaredField("loadedCoremods"); + reparsedCoremodsField.setAccessible(true); + loadedCoremodsField.setAccessible(true); + final ArrayList reparsedCoremods = (ArrayList) reparsedCoremodsField.get(CoreModManager.class); + final ArrayList loadedCoremods = (ArrayList) loadedCoremodsField.get(CoreModManager.class); + for (int idx = reparsedCoremods.size() - 1; idx >= 0; idx--) { + final String coreMod = reparsedCoremods.get(idx); + if (coreMod.startsWith("optimizationsandtweaks")) { + LOGGER.info("Removing reparsed coremod " + coreMod); + loadedCoremods.add(reparsedCoremods.remove(idx)); + + } + } + } catch (Exception e) { + throw new RuntimeException(e); + } + try { + final ArrayList mixinConfigsDefault = (ArrayList) Launch.blackboard.get("mixin.configs.default"); + if (mixinConfigsDefault != null) { + for (int idx = mixinConfigsDefault.size() - 1; idx >= 0; idx--) { + final String name = mixinConfigsDefault.get(idx); + if (name.contains("optimizationsandtweaks")) { + LOGGER.info("Removing mixin config " + name); + mixinConfigsDefault.remove(idx); + } + } + } + final Set mixinConfigs = (Set) Launch.blackboard.get("mixin.configs.queue"); + final Set toRemove = new HashSet<>(); + if (mixinConfigs != null) { + for (Config config : mixinConfigs) { + if (config.getName().contains("optimizationsandtweaks")) { + LOGGER.info("Removing queued mixin config " + config.getName()); + toRemove.add(config); + } + } + mixinConfigs.removeAll(toRemove); + } + final MixinPlatformManager platformManager = (MixinPlatformManager) Launch.blackboard.get("mixin.platform"); + if (platformManager != null) { + final Field containersField = platformManager.getClass().getDeclaredField("containers"); + containersField.setAccessible(true); + final Map containers = (Map) containersField.get(platformManager); + for (Map.Entry entry : containers.entrySet()) { + if(entry.getKey().getAttribute("MixinConfigs").contains("optimizationsandtweaks")) { + LOGGER.info("Removing mixin container " + entry.getKey().toString()); + containers.remove(entry.getKey()); + } + } + } + } catch (Exception e) { throw new RuntimeException(e); }