Add Opticrash detection

This commit is contained in:
embeddedt 2023-04-25 12:03:19 -04:00
parent e771af2330
commit e46910f3c1
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
3 changed files with 22 additions and 3 deletions

View File

@ -53,6 +53,9 @@ public class ModernFixMixinPlugin implements IMixinConfigPlugin {
this.logger.info("Loaded configuration file for ModernFix: {} options available, {} override(s) found", this.logger.info("Loaded configuration file for ModernFix: {} options available, {} override(s) found",
config.getOptionCount(), config.getOptionOverrideCount()); config.getOptionCount(), config.getOptionOverrideCount());
if(ModernFixEarlyConfig.OPTIFINE_PRESENT)
this.logger.fatal("OptiFine detected. Use of ModernFix with OptiFine is not supported due to its impact on launch time and breakage of Forge features.");
try { try {
Class.forName("sun.misc.Unsafe").getDeclaredMethod("defineAnonymousClass", Class.class, byte[].class, Object[].class); Class.forName("sun.misc.Unsafe").getDeclaredMethod("defineAnonymousClass", Class.class, byte[].class, Object[].class);
} catch(ReflectiveOperationException | NullPointerException e) { } catch(ReflectiveOperationException | NullPointerException e) {

View File

@ -14,8 +14,23 @@ public class ModernFixEarlyConfig {
private final Map<String, Option> options = new HashMap<>(); private final Map<String, Option> options = new HashMap<>();
public static final boolean OPTIFINE_PRESENT;
static {
boolean hasOfClass = false;
try {
Class.forName("optifine.OptiFineTransformationService");
hasOfClass = true;
} catch(Throwable e) {
}
OPTIFINE_PRESENT = hasOfClass;
}
private static boolean modPresent(String modId) { private static boolean modPresent(String modId) {
return FMLLoader.getLoadingModList().getModFileById(modId) != null; if(modId.equals("optifine"))
return OPTIFINE_PRESENT;
else
return FMLLoader.getLoadingModList().getModFileById(modId) != null;
} }
private ModernFixEarlyConfig() { private ModernFixEarlyConfig() {
@ -87,11 +102,12 @@ public class ModernFixEarlyConfig {
disableIfModPresent("mixin.perf.compress_biome_container", "chocolate", "betterendforge"); disableIfModPresent("mixin.perf.compress_biome_container", "chocolate", "betterendforge");
disableIfModPresent("mixin.bugfix.mc218112", "performant"); disableIfModPresent("mixin.bugfix.mc218112", "performant");
disableIfModPresent("mixin.perf.reuse_datapacks", "tac"); disableIfModPresent("mixin.perf.reuse_datapacks", "tac");
disableIfModPresent("mixin.launch.class_search_cache", "optifine");
} }
private void disableIfModPresent(String configName, String... ids) { private void disableIfModPresent(String configName, String... ids) {
for(String id : ids) { for(String id : ids) {
if(FMLLoader.getLoadingModList().getModFileById(id) != null) { if(modPresent(id)) {
Option option = this.options.get(configName); Option option = this.options.get(configName);
if(option != null) if(option != null)
option.addModOverride(false, id); option.addModOverride(false, id);

View File

@ -52,7 +52,7 @@ public class WindowMixin {
* Grab the original width/height from the window and inject them into our state variables. * Grab the original width/height from the window and inject them into our state variables.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/loading/progress/EarlyProgressVisualization;handOffWindow(Ljava/util/function/IntSupplier;Ljava/util/function/IntSupplier;Ljava/util/function/Supplier;Ljava/util/function/LongSupplier;)J")) @Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/loading/progress/EarlyProgressVisualization;handOffWindow(Ljava/util/function/IntSupplier;Ljava/util/function/IntSupplier;Ljava/util/function/Supplier;Ljava/util/function/LongSupplier;)J"), require = 0)
private long performHandoff(EarlyProgressVisualization instance, IntSupplier width, IntSupplier height, Supplier<String> title, LongSupplier monitor) { private long performHandoff(EarlyProgressVisualization instance, IntSupplier width, IntSupplier height, Supplier<String> title, LongSupplier monitor) {
Object visualizer = getEarlyProgressVisualizer(); Object visualizer = getEarlyProgressVisualizer();
if(visualizer != null) { if(visualizer != null) {