Skip to content

Commit 631b3ed

Browse files
committed
Detect Redirector and show warnings
1 parent 98e6af8 commit 631b3ed

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

common/src/main/resources/assets/modernfix/lang/en_us.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"modernfix.no_lazydfu": "LazyDFU is not installed. If Minecraft needs to update game data from an older version, there may be noticeable lag.",
66
"modernfix.no_ferritecore": "FerriteCore is not installed. Memory usage will be very high.",
77
"modernfix.connectedness_dynresoruces": "Connectedness and ModernFix's dynamic resources option are not compatible. Remove Connectedness or disable dynamic resources in the ModernFix config.",
8-
"modernfix.perf_mod_warning": "It is recommended to install the mods, but the warning(s) can be disabled in the ModernFix config.",
8+
"modernfix.perf_mod_warning": "ModernFix mod warnings can be disabled by turning off mixin.feature.warn_missing_perf_mods in the ModernFix config.",
9+
"modernfix.redirector_installed": "ModernFix detected that Redirector is installed. Redirector is known to cause many strange and hard-to-debug issues, and removing it is strongly recommended.",
910
"modernfix.config": "ModernFix mixin config",
1011
"modernfix.config.done_restart": "Done (restart required)",
1112
"modernfix.config.wiki": "Open wiki",

forge/src/main/java/org/embeddedt/modernfix/forge/init/ModernFixForge.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import net.minecraftforge.registries.RegisterEvent;
2525
import net.minecraftforge.server.ServerLifecycleHooks;
2626
import org.apache.commons.lang3.tuple.Pair;
27+
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
2728
import org.embeddedt.modernfix.ModernFix;
2829
import org.embeddedt.modernfix.core.ModernFixMixinPlugin;
2930
import org.embeddedt.modernfix.entity.EntityDataIDSyncHandler;
@@ -89,6 +90,28 @@ private void registerItems(RegisterEvent event) {
8990
Pair.of(ImmutableList.of("ferritecore"), "modernfix.no_ferritecore")
9091
);
9192

93+
/**
94+
* Redirector 5.0 redirects ALL Enum.values() calls to use a cached array, which breaks any code that mutates
95+
* the given array, and causes all sorts of impossible to debug issues in mods. We complain loudly when it is
96+
* installed now.
97+
*/
98+
private static boolean hasDangerousRedirectorInstalled() {
99+
try {
100+
var clz = Class.forName("com.teampotato.redirector.RedirectorLaunchPluginService");
101+
var pkg = clz.getPackage();
102+
if (pkg != null) {
103+
String implVer = pkg.getImplementationVersion();
104+
var artifactVer = new DefaultArtifactVersion(implVer);
105+
return artifactVer.getMajorVersion() == 5;
106+
}
107+
} catch(Exception e) {
108+
if (!(e instanceof ClassNotFoundException)) {
109+
ModernFix.LOGGER.error("Error detecting Redirector", e);
110+
}
111+
}
112+
return false;
113+
}
114+
92115
@SubscribeEvent
93116
public void commonSetup(FMLCommonSetupEvent event) {
94117
if(ModernFixMixinPlugin.instance.isOptionEnabled("feature.warn_missing_perf_mods.Warnings")) {
@@ -101,6 +124,11 @@ public void commonSetup(FMLCommonSetupEvent event) {
101124
ModLoader.get().addWarning(new ModLoadingWarning(ModLoadingContext.get().getActiveContainer().getModInfo(), ModLoadingStage.COMMON_SETUP, warning.getRight()));
102125
}
103126
}
127+
if (hasDangerousRedirectorInstalled()) {
128+
ModernFix.LOGGER.fatal("Redirector 5.x is detected, it is known to cause extremely hard-to-debug issues in other mods");
129+
ModLoader.get().addWarning(new ModLoadingWarning(ModLoadingContext.get().getActiveContainer().getModInfo(), ModLoadingStage.COMMON_SETUP, "modernfix.redirector_installed"));
130+
atLeastOneWarning = true;
131+
}
104132
if(atLeastOneWarning)
105133
ModLoader.get().addWarning(new ModLoadingWarning(ModLoadingContext.get().getActiveContainer().getModInfo(), ModLoadingStage.COMMON_SETUP, "modernfix.perf_mod_warning"));
106134
});

0 commit comments

Comments
 (0)