Skip to content

Commit

Permalink
Handle more incompatible mods
Browse files Browse the repository at this point in the history
* Removes reparsable coremod so they don't get injected as a mod later
* Removes any registered mixin configs
  • Loading branch information
mitchej123 committed Nov 16, 2024
1 parent 7fb8cde commit a118286
Showing 1 changed file with 75 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -23,8 +32,8 @@ public void acceptOptions(List<String> 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){
Expand All @@ -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<IClassTransformer> xformers = (List<IClassTransformer>) xformersField.get(lcl);
Expand All @@ -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<IClassTransformer> xformers = (List<IClassTransformer>) xformersField.get(lcl);
final List<IClassTransformer> xformers = (List<IClassTransformer>) 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")) {
Expand All @@ -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<String> containers = (List<String> ) injectedContainersField.get(Loader.class);
final List<String> containers = (List<String> ) 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<String> reparsedCoremods = (ArrayList<String>) reparsedCoremodsField.get(CoreModManager.class);
final ArrayList<String> loadedCoremods = (ArrayList<String>) 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<String> mixinConfigsDefault = (ArrayList<String>) 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<Config> mixinConfigs = (Set<Config>) Launch.blackboard.get("mixin.configs.queue");
final Set<Config> 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<IContainerHandle, MixinContainer> containers = (Map<IContainerHandle, MixinContainer>) containersField.get(platformManager);
for (Map.Entry<IContainerHandle, MixinContainer> 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);
}
Expand Down

0 comments on commit a118286

Please sign in to comment.