diff --git a/src/main/java/vfyjxf/bettercrashes/mixins/early/CrashReportMixin.java b/src/main/java/vfyjxf/bettercrashes/mixins/early/CrashReportMixin.java index f55db2a..123ace4 100644 --- a/src/main/java/vfyjxf/bettercrashes/mixins/early/CrashReportMixin.java +++ b/src/main/java/vfyjxf/bettercrashes/mixins/early/CrashReportMixin.java @@ -26,6 +26,7 @@ import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -60,23 +61,33 @@ public class CrashReportMixin implements IPatchedCrashReport { return null; } - private Set suspectedMods; + @Unique + private Set betterCrashes$suspectedMods; @Override - public Set getSuspectedMods() { - return suspectedMods; + public Set betterCrashes$getSuspectedMods() { + return betterCrashes$suspectedMods; + } + + /** @reason Deobfuscates the stacktrace using MCP mappings */ + @Inject(method = "populateEnvironment", at = @At("HEAD")) + private void betterCrashes$beforePopulateEnvironment(CallbackInfo ci) { + if (BetterCrashesConfig.stacktraceDeobfuscation) { + StacktraceDeobfuscator.init(new File(String.format("%s-stackdeobfuscator-methods.csv", MODID))); + } + StacktraceDeobfuscator.deobfuscateThrowable(cause); } /** @reason Adds a list of mods which may have caused the crash to the report. */ @Inject(method = "populateEnvironment", at = @At("TAIL")) - private void afterPopulateEnvironment(CallbackInfo ci) { + private void betterCrashes$afterPopulateEnvironment(CallbackInfo ci) { theReportCategory.addCrashSectionCallable("Suspected Mods", () -> { try { - suspectedMods = ModIdentifier.identifyFromStacktrace(cause); + betterCrashes$suspectedMods = ModIdentifier.identifyFromStacktrace(cause); String modListString = "Unknown"; List modNames = new ArrayList<>(); - for (ModContainer mod : suspectedMods) { + for (ModContainer mod : betterCrashes$suspectedMods) { modNames.add(mod.getName() + " (" + mod.getModId() + ")"); } @@ -90,15 +101,6 @@ public class CrashReportMixin implements IPatchedCrashReport { }); } - /** @reason Deobfuscates the stacktrace using MCP mappings */ - @Inject(method = "populateEnvironment", at = @At("HEAD")) - private void beforePopulateEnvironment(CallbackInfo ci) { - if (BetterCrashesConfig.stacktraceDeobfuscation) { - StacktraceDeobfuscator.init(new File(String.format("%s-stackdeobfuscator-methods.csv", MODID))); - } - StacktraceDeobfuscator.deobfuscateThrowable(cause); - } - /** * @reason Improve report formatting * @author Runemoro @@ -106,11 +108,13 @@ public class CrashReportMixin implements IPatchedCrashReport { @Overwrite public String getCompleteReport() { StringBuilder builder = new StringBuilder(); - - builder.append("---- Minecraft Crash Report ----\n").append("// ").append(getVanillaFixComment()).append("\n\n") - .append("Time: ").append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z").format(new Date())).append("\n") + builder.append("---- Minecraft Crash Report ----\n").append("// ").append(betterCrashes$getVanillaFixComment()) + .append("\n\n").append("Time: ") + .append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z").format(new Date())).append("\n") .append("Description: ").append(description).append("\n\n") - .append(stacktraceToString(cause).replace("\t", " ")) // Vanilla's getCauseStackTraceOrString doesn't + .append(betterCrashes$stacktraceToString(cause).replace("\t", " ")) // Vanilla's + // getCauseStackTraceOrString + // doesn't // print causes and suppressed // exceptions .append( @@ -125,7 +129,8 @@ public class CrashReportMixin implements IPatchedCrashReport { return builder.toString().replace("\t", " "); } - private static String stacktraceToString(Throwable cause) { + @Unique + private static String betterCrashes$stacktraceToString(Throwable cause) { StringWriter writer = new StringWriter(); cause.printStackTrace(new PrintWriter(writer)); return writer.toString(); @@ -141,19 +146,18 @@ public class CrashReportMixin implements IPatchedCrashReport { crashreportcategory.appendToStringBuilder(builder); builder.append("\n"); } - theReportCategory.appendToStringBuilder(builder); } - private String getVanillaFixComment() { + @Unique + private String betterCrashes$getVanillaFixComment() { try { - if (Math.random() < 0.01 && !suspectedMods.isEmpty()) { - ModContainer mod = suspectedMods.iterator().next(); + if (Math.random() < 0.01 && !betterCrashes$suspectedMods.isEmpty()) { + ModContainer mod = betterCrashes$suspectedMods.iterator().next(); String author = mod.getMetadata().authorList.get(0); return "I blame " + author + "."; } } catch (Throwable ignored) {} - return getWittyComment(); } } diff --git a/src/main/java/vfyjxf/bettercrashes/mixins/early/MinecraftMixin.java b/src/main/java/vfyjxf/bettercrashes/mixins/early/MinecraftMixin.java index 02dad12..fbcce01 100644 --- a/src/main/java/vfyjxf/bettercrashes/mixins/early/MinecraftMixin.java +++ b/src/main/java/vfyjxf/bettercrashes/mixins/early/MinecraftMixin.java @@ -6,8 +6,6 @@ package vfyjxf.bettercrashes.mixins.early; -import java.io.IOException; -import java.util.List; import java.util.Queue; import net.minecraft.client.Minecraft; @@ -42,6 +40,7 @@ import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import cpw.mods.fml.client.SplashProgress; import cpw.mods.fml.common.Loader; @@ -89,9 +88,6 @@ public abstract class MinecraftMixin { @Shadow public GuiIngame ingameGUI; - @Shadow - private List defaultResourcePacks; - @Shadow private IReloadableResourceManager mcResourceManager; @@ -159,8 +155,11 @@ public abstract class MinecraftMixin { @Shadow public abstract void func_147120_f(); // func_147120_f --> resetSize - private int clientCrashCount = 0; - private int serverCrashCount = 0; + @Unique + private int betterCrashes$clientCrashCount = 0; + + @Unique + private int betterCrashes$serverCrashCount = 0; /** * @author Runemoro @@ -174,7 +173,7 @@ public abstract class MinecraftMixin { } catch (Throwable throwable) { CrashReport crashReport = CrashReport.makeCrashReport(throwable, "Initializing game"); crashReport.makeCategory("Initialization"); - displayInitErrorScreen(addGraphicsAndWorldToCrashReport(crashReport)); + betterCrashes$displayInitErrorScreen(addGraphicsAndWorldToCrashReport(crashReport)); return; } try { @@ -183,26 +182,26 @@ public abstract class MinecraftMixin { try { runGameLoop(); } catch (ReportedException e) { - clientCrashCount++; + betterCrashes$clientCrashCount++; addGraphicsAndWorldToCrashReport(e.getCrashReport()); - addInfoToCrash(e.getCrashReport()); - resetGameState(); + betterCrashes$addInfoToCrash(e.getCrashReport()); + betterCrashes$resetGameState(); logger.fatal("Reported exception thrown!", e); - displayCrashScreen(e.getCrashReport()); + betterCrashes$displayCrashScreen(e.getCrashReport()); } catch (Throwable e) { - clientCrashCount++; + betterCrashes$clientCrashCount++; CrashReport report = new CrashReport("Unexpected error", e); addGraphicsAndWorldToCrashReport(report); - addInfoToCrash(report); - resetGameState(); + betterCrashes$addInfoToCrash(report); + betterCrashes$resetGameState(); logger.fatal("Unreported exception thrown!", e); - displayCrashScreen(report); + betterCrashes$displayCrashScreen(report); } } else { - serverCrashCount++; - addInfoToCrash(crashReporter); + betterCrashes$serverCrashCount++; + betterCrashes$addInfoToCrash(crashReporter); freeMemory(); - displayCrashScreen(crashReporter); + betterCrashes$displayCrashScreen(crashReporter); hasCrashed = false; crashReporter = null; } @@ -213,12 +212,20 @@ public abstract class MinecraftMixin { } /** - * @param report * @author Runemoro + * @reason Overwrite Minecraft.displayCrashReport */ - public void displayCrashScreen(CrashReport report) { + @Overwrite + public void displayCrashReport(CrashReport report) { + if (betterCrashes$shouldGenerateCrashLog()) { + CrashUtils.outputReport(report); + } + } + + @Unique + private void betterCrashes$displayCrashScreen(CrashReport report) { try { - if (shouldGenerateCrashLog()) { + if (betterCrashes$shouldGenerateCrashLog()) { CrashUtils.outputReport(report); } @@ -245,18 +252,21 @@ public abstract class MinecraftMixin { } } - private void addInfoToCrash(CrashReport crashReport) { - crashReport.getCategory() - .addCrashSectionCallable("Client Crashes Since Restart", () -> String.valueOf(clientCrashCount)); + @Unique + private void betterCrashes$addInfoToCrash(CrashReport crashReport) { + crashReport.getCategory().addCrashSectionCallable( + "Client Crashes Since Restart", + () -> String.valueOf(betterCrashes$clientCrashCount)); crashReport.getCategory().addCrashSectionCallable( "Integrated Server Crashes Since Restart", - () -> String.valueOf(serverCrashCount)); + () -> String.valueOf(betterCrashes$serverCrashCount)); } /** * @author Runemoro */ - public void resetGameState() { + @Unique + private void betterCrashes$resetGameState() { try { // Free up memory such that this works properly in case of an OutOfMemoryError int originalMemoryReserveSize = -1; @@ -294,11 +304,11 @@ public abstract class MinecraftMixin { } /** - * @param report * @author Runemoro */ - public void displayInitErrorScreen(CrashReport report) { - if (shouldGenerateCrashLog()) { + @Unique + private void betterCrashes$displayInitErrorScreen(CrashReport report) { + if (betterCrashes$shouldGenerateCrashLog()) { CrashUtils.outputReport(report); } try { @@ -325,7 +335,7 @@ public abstract class MinecraftMixin { // noinspection deprecation SplashProgress.finish(); // Disable the forge splash progress screen } catch (Throwable ignored) {} - runGUILoop(new GuiInitErrorScreen(report)); + betterCrashes$runGUILoop(new GuiInitErrorScreen(report)); } catch (Throwable t) { logger.error( "An uncaught exception occured while displaying the init error screen, making normal report instead", @@ -336,10 +346,10 @@ public abstract class MinecraftMixin { } /** - * @param screen * @author Runemoro */ - private void runGUILoop(GuiScreen screen) throws IOException { + @Unique + private void betterCrashes$runGUILoop(GuiScreen screen) { displayGuiScreen(screen); while (running && currentScreen != null && !(currentScreen instanceof GuiMainMenu) @@ -398,20 +408,9 @@ public abstract class MinecraftMixin { } } - /** - * @param report - * @author Runemoro - * @reason - */ - @Overwrite - public void displayCrashReport(CrashReport report) { - if (shouldGenerateCrashLog()) { - CrashUtils.outputReport(report); - } - } - - public boolean shouldGenerateCrashLog() { - return clientCrashCount <= BetterCrashesConfig.crashLogLimitClient - && serverCrashCount <= BetterCrashesConfig.crashLogLimitServer; + @Unique + private boolean betterCrashes$shouldGenerateCrashLog() { + return betterCrashes$clientCrashCount <= BetterCrashesConfig.crashLogLimitClient + && betterCrashes$serverCrashCount <= BetterCrashesConfig.crashLogLimitServer; } } diff --git a/src/main/java/vfyjxf/bettercrashes/utils/GuiProblemScreen.java b/src/main/java/vfyjxf/bettercrashes/utils/GuiProblemScreen.java index a21917a..68ee26d 100644 --- a/src/main/java/vfyjxf/bettercrashes/utils/GuiProblemScreen.java +++ b/src/main/java/vfyjxf/bettercrashes/utils/GuiProblemScreen.java @@ -205,7 +205,7 @@ public abstract class GuiProblemScreen extends GuiScreen { protected String getModListString() { if (modListString == null) { - final Set suspectedMods = ((IPatchedCrashReport) report).getSuspectedMods(); + final Set suspectedMods = ((IPatchedCrashReport) report).betterCrashes$getSuspectedMods(); if (suspectedMods == null) { return modListString = I18n.format("bettercrashes.gui.common.identificationErrored"); } diff --git a/src/main/java/vfyjxf/bettercrashes/utils/IPatchedCrashReport.java b/src/main/java/vfyjxf/bettercrashes/utils/IPatchedCrashReport.java index 95b94b0..6b94512 100644 --- a/src/main/java/vfyjxf/bettercrashes/utils/IPatchedCrashReport.java +++ b/src/main/java/vfyjxf/bettercrashes/utils/IPatchedCrashReport.java @@ -15,5 +15,5 @@ import cpw.mods.fml.common.ModContainer; */ public interface IPatchedCrashReport { - Set getSuspectedMods(); + Set betterCrashes$getSuspectedMods(); }