diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a94ba54 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +.git +.gradle +.idea +.settings +.metadata +bin +build +run +minecraft +eclipse +.classpath +.project +.apt_generated +.apt_generated_tests + +*.bat +*.sh +*.iml +*.ipr +*.iws +*.launch +.factorypath + +forge*changelog.txt diff --git a/README.md b/README.md index 38a9726..e7d62c2 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,10 @@ # BetterCrashes + BetterCrashes is a port of VanillaFix's crash improvement features to Minecraft 1.7.10. + +Most of the code comes from VanillaFix, I just make them work on Minecraft 1.7.10. + +Requires [Grimoire](https://github.com/CrucibleMC/Grimoire) mod to work + +# Credits +Thanks VanillaFix and Grimoire \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..b4c357a --- /dev/null +++ b/build.gradle @@ -0,0 +1,81 @@ +buildscript { + repositories { + mavenCentral() + jcenter() + maven { + name = "github" + url = "https://github.com/juanmuscaria/maven/raw/master" + } + } + dependencies { + classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-1.4.0-SNAPSHOT' + classpath 'com.integral.grimoire:GrimoireShenanigans:[1.3.0,)' + } +} + + +apply plugin: 'java' +apply plugin: 'forge' +apply plugin: 'grimoire-shenanigans' + +[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' +sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' + +version = mod_version +group = mod_group +archivesBaseName = mod_archives_name + +minecraft { + version = "1.7.10-10.13.4.1614-1.7.10" + runDir = "eclipse" + replace "@VERSION@", project.version +} + +repositories { + + flatDir { + dirs 'libs' + } +} + +processResources { + + from(sourceSets.main.resources.srcDirs) { + include 'mcmod.info' + expand 'version': project.version, + 'mod_id': mod_id, + 'mod_name': mod_name, + 'mod_author': mod_author, + 'mod_description': mod_description, + 'mc_version': mc_version, + 'mod_version': mod_version, + 'mod_icon': mod_icon + } + + from(sourceSets.main.resources.srcDirs) { + exclude 'mcmod.info' + } +} + +task devJar(type: Jar) { + classifier = 'dev' + from sourceSets.main.output +} + +task sourcesJar(type: Jar) { + classifier = 'sources' + from sourceSets.main.allSource +} + +jar{ + appendix project.minecraft.version +} + +reobf { + addExtraSrgFile project.mixinSrg +} + +artifacts { + archives devJar + archives sourcesJar +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..15c7a45 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,20 @@ +# Gradle Specifications +org.gradle.jvmargs=-Xmx2G -Xms2G +org.gradle.daemon=false + +# General Specifications +mc_version=1.7.10 +mod_version=1.0.0 +forge_version=10.13.4.1614 +mod_group=vfyjxf.bettercrashes +mod_id=bettercrashes +mod_name=BetterCrashes +mod_archives_name=BetterCrashes +mod_author=vfyjxf +mod_icon=TEM_logo.png +mod_description=Some generic mod description +mod_credits=Me, for making this amazing mod. + +# Grimoire Shenanigans +mixinRefmapName=mixins.bettercrashes.refmap.json +grimoireVersion=[3.2.0,) \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..b761216 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..f0b5a51 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Wed Jul 02 15:54:47 CDT 2014 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..91a7e26 --- /dev/null +++ b/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/src/main/java/vfyjxf/bettercrashes/BetterCrashes.java b/src/main/java/vfyjxf/bettercrashes/BetterCrashes.java new file mode 100644 index 0000000..003325a --- /dev/null +++ b/src/main/java/vfyjxf/bettercrashes/BetterCrashes.java @@ -0,0 +1,17 @@ +package vfyjxf.bettercrashes; + + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import cpw.mods.fml.common.Mod; + +@Mod(modid = BetterCrashes.MODID, version = BetterCrashes.VERSION, name = BetterCrashes.NAME, dependencies = BetterCrashes.DEPENDENCIES) +public class BetterCrashes { + public static final String MODID = "bettercrashes"; + public static final String NAME = "BetterCrashes"; + public static final String VERSION = "@VERSION@"; + public static final String DEPENDENCIES = "required-after:grimoire@[3.2.3,]"; + + public static final Logger logger = LogManager.getLogger("BetterCrashes"); +} diff --git a/src/main/java/vfyjxf/bettercrashes/BetterCrashesGrimmix.java b/src/main/java/vfyjxf/bettercrashes/BetterCrashesGrimmix.java new file mode 100644 index 0000000..86aaa53 --- /dev/null +++ b/src/main/java/vfyjxf/bettercrashes/BetterCrashesGrimmix.java @@ -0,0 +1,23 @@ +package vfyjxf.bettercrashes; + +import io.github.crucible.grimoire.common.api.grimmix.Grimmix; +import io.github.crucible.grimoire.common.api.grimmix.GrimmixController; +import io.github.crucible.grimoire.common.api.grimmix.lifecycle.IConfigBuildingEvent; + +@Grimmix(id = "bettercrashesgrimmix", name = "Better Crashes Grimmix") +public class BetterCrashesGrimmix extends GrimmixController { + + @Override + public void buildMixinConfigs(IConfigBuildingEvent event) { + event.createBuilder("bettercrashes/mixins.bettercrash.json") + .mixinPackage("vfyjxf.bettercrashes.mixins") + .clientMixins("client.MixinMinecraft") + .commonMixins("MixinCrashReport") + .refmap("@MIXIN_REFMAP@") + .verbose(true) + .required(true) + .build(); + } + + +} diff --git a/src/main/java/vfyjxf/bettercrashes/mixins/MixinCrashReport.java b/src/main/java/vfyjxf/bettercrashes/mixins/MixinCrashReport.java new file mode 100644 index 0000000..4b366c2 --- /dev/null +++ b/src/main/java/vfyjxf/bettercrashes/mixins/MixinCrashReport.java @@ -0,0 +1,127 @@ +package vfyjxf.bettercrashes.mixins; + +import cpw.mods.fml.common.ModContainer; +import net.minecraft.crash.CrashReport; +import net.minecraft.crash.CrashReportCategory; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.exception.ExceptionUtils; +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.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import vfyjxf.bettercrashes.utils.IPatchedCrashReport; +import vfyjxf.bettercrashes.utils.ModIdentifier; +import vfyjxf.bettercrashes.utils.StacktraceDeobfuscator; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Set; + +@Mixin(value = CrashReport.class,priority = 500) +public class MixinCrashReport implements IPatchedCrashReport { + @Shadow @Final private CrashReportCategory theReportCategory; + @Shadow @Final private Throwable cause; + @Shadow @Final private List crashReportSections; + @Shadow @Final private String description; + + @Shadow private static String getWittyComment() { return null; } + + private Set suspectedMods; + @Override + public Set getSuspectedMods() { + return suspectedMods; + } + /** @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) { + theReportCategory.addCrashSectionCallable("Suspected Mods", () -> { + try { + suspectedMods = ModIdentifier.identifyFromStacktrace(cause); + + String modListString = "Unknown"; + List modNames = new ArrayList<>(); + for (ModContainer mod : suspectedMods) { + modNames.add(mod.getName() + " (" + mod.getModId() + ")"); + } + + if (!modNames.isEmpty()) { + modListString = StringUtils.join(modNames, ", "); + } + return modListString; + } catch (Throwable e) { + return ExceptionUtils.getStackTrace(e).replace("\t", " "); + } + }); + } + + /** @reason Deobfuscates the stacktrace using MCP mappings */ + @Inject(method = "populateEnvironment", at = @At("HEAD")) + private void beforePopulateEnvironment(CallbackInfo ci) { + StacktraceDeobfuscator.deobfuscateThrowable(cause); + } + + /** + * @reason Improve report formatting + * @author Runemoro + */ + @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") + .append("Description: ").append(description) + .append("\n\n") + .append(stacktraceToString(cause).replace("\t", " ")) // Vanilla's getCauseStackTraceOrString doesn't print causes and suppressed exceptions + .append("\n\nA detailed walkthrough of the error, its code path and all known details is as follows:\n"); + + for (int i = 0; i < 87; i++) { + builder.append("-"); + } + + builder.append("\n\n"); + getSectionsInStringBuilder(builder); + return builder.toString().replace("\t", " "); + } + + private static String stacktraceToString(Throwable cause) { + StringWriter writer = new StringWriter(); + cause.printStackTrace(new PrintWriter(writer)); + return writer.toString(); + } + + /** + * @reason Improve report formatting, add VanillaFix comment + * @author Runemoro + */ + @Overwrite + public void getSectionsInStringBuilder(StringBuilder builder) { + for (CrashReportCategory crashreportcategory : crashReportSections) { + crashreportcategory.appendToStringBuilder(builder); + builder.append("\n"); + } + + theReportCategory.appendToStringBuilder(builder); + } + + private String getVanillaFixComment() { + try { + if (Math.random() < 0.01 && !suspectedMods.isEmpty()) { + ModContainer mod = 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/client/MixinMinecraft.java b/src/main/java/vfyjxf/bettercrashes/mixins/client/MixinMinecraft.java new file mode 100644 index 0000000..185215f --- /dev/null +++ b/src/main/java/vfyjxf/bettercrashes/mixins/client/MixinMinecraft.java @@ -0,0 +1,299 @@ +package vfyjxf.bettercrashes.mixins.client; + + +import cpw.mods.fml.client.SplashProgress; +import cpw.mods.fml.common.Loader; +import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.SoundHandler; +import net.minecraft.client.gui.*; +import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.client.network.NetHandlerPlayClient; +import net.minecraft.client.renderer.EntityRenderer; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.resources.IReloadableResourceManager; +import net.minecraft.client.resources.LanguageManager; +import net.minecraft.client.resources.SimpleReloadableResourceManager; +import net.minecraft.client.resources.data.IMetadataSerializer; +import net.minecraft.client.settings.GameSettings; +import net.minecraft.client.shader.Framebuffer; +import net.minecraft.crash.CrashReport; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.MinecraftError; +import net.minecraft.util.ReportedException; +import net.minecraft.util.ResourceLocation; +import org.apache.logging.log4j.Logger; +import org.lwjgl.LWJGLException; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.Display; +import org.lwjgl.opengl.GL11; +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 vfyjxf.bettercrashes.utils.CrashUtils; +import vfyjxf.bettercrashes.utils.GuiCrashScreen; +import vfyjxf.bettercrashes.utils.GuiInitErrorScreen; +import vfyjxf.bettercrashes.utils.StateManager; + +import java.io.IOException; +import java.util.List; +import java.util.Queue; + + +@Mixin(Minecraft.class) +public abstract class MixinMinecraft{ + + @Shadow @Final private static Logger logger; + @Shadow volatile boolean running; + @Shadow private boolean hasCrashed; + @Shadow private CrashReport crashReporter; + @Shadow public static byte[] memoryReserve; + @Shadow @Final private Queue field_152351_aB;// field_152351_aB --> scheduledTasks + @Shadow public EntityRenderer entityRenderer; + @Shadow private long field_83002_am;//field_83002_am-->debugCrashKeyPressTime + @Shadow public GameSettings gameSettings; + @Shadow public GuiIngame ingameGUI; + @Shadow private List defaultResourcePacks; + @Shadow private IReloadableResourceManager mcResourceManager; + @Shadow public FontRenderer fontRenderer; + @Shadow public TextureManager renderEngine; + @Shadow private LanguageManager mcLanguageManager; + @Shadow private SoundHandler mcSoundHandler; + @Shadow @Final private IMetadataSerializer metadataSerializer_; + @Shadow private Framebuffer framebufferMc; + @Shadow public GuiScreen currentScreen; + @Shadow private int leftClickCounter; + @Shadow public int displayWidth; + @Shadow public int displayHeight; + + @Shadow protected abstract void startGame() throws LWJGLException; + @Shadow public abstract void displayGuiScreen(GuiScreen guiScreenIn); + @Shadow public abstract CrashReport addGraphicsAndWorldToCrashReport(CrashReport theCrash); + + @Shadow protected abstract void runGameLoop(); + + @Shadow public abstract NetHandlerPlayClient getNetHandler(); + + @Shadow public abstract void loadWorld(WorldClient worldClientIn); + + @Shadow public abstract void freeMemory(); + + @Shadow public abstract void shutdownMinecraftApplet(); + + @Shadow public abstract void refreshResources(); + + @Shadow protected abstract void checkGLError(String message); + + @Shadow public abstract void func_147120_f();// func_147120_f --> resetSize + + private int clientCrashCount = 0; + private int serverCrashCount = 0; + + /** + * @author Runemoro + * @reason Overwrite Minecraft.run() + */ + @Overwrite + public void run(){ + running = true; + try { + startGame(); + } catch (Throwable throwable) { + CrashReport crashReport = CrashReport.makeCrashReport(throwable, "Initializing game"); + crashReport.makeCategory("Initialization"); + displayInitErrorScreen(addGraphicsAndWorldToCrashReport(crashReport)); + return; + } + try { + while (running) { + if (!hasCrashed || crashReporter == null) { + try { + runGameLoop(); + } catch (ReportedException e) { + clientCrashCount++; + addGraphicsAndWorldToCrashReport(e.getCrashReport()); + addInfoToCrash(e.getCrashReport()); + resetGameState(); + logger.fatal("Reported exception thrown!", e); + displayCrashScreen(e.getCrashReport()); + } catch (Throwable e) { + clientCrashCount++; + CrashReport report = new CrashReport("Unexpected error", e); + addGraphicsAndWorldToCrashReport(report); + addInfoToCrash(report); + resetGameState(); + logger.fatal("Unreported exception thrown!", e); + displayCrashScreen(report); + } + } else { + serverCrashCount++; + addInfoToCrash(crashReporter); + freeMemory(); + displayCrashScreen(crashReporter); + hasCrashed = false; + crashReporter = null; + } + } + } catch (MinecraftError ignored) { + } finally { + shutdownMinecraftApplet(); + } + + } + + public void displayCrashScreen(CrashReport report) { + try { + CrashUtils.outputReport(report); + + // Reset hasCrashed, debugCrashKeyPressTime, and crashIntegratedServerNextTick + hasCrashed = false; + field_83002_am = -1; +// crashIntegratedServerNextTick = false; + + // Vanilla does this when switching to main menu but not our custom crash screen + // nor the out of memory screen (see https://bugs.mojang.com/browse/MC-128953) + gameSettings.showDebugInfo = false; + ingameGUI.getChatGUI().clearChatMessages(); + + // Display the crash screen +// runGUILoop(new GuiCrashScreen(report)); + displayGuiScreen(new GuiCrashScreen(report)); + } catch (Throwable t) { + // The crash screen has crashed. Report it normally instead. + logger.error("An uncaught exception occured while displaying the crash screen, making normal report instead", t); + displayCrashReport(report); + System.exit(report.getFile() != null ? -1 : -2); + } + } + + private void addInfoToCrash(CrashReport crashReport){ + crashReport.getCategory().addCrashSectionCallable("Client Crashes Since Restart",() -> String.valueOf(clientCrashCount)); + crashReport.getCategory().addCrashSectionCallable("Integrated Server Crashes Since Restart", () -> String.valueOf(serverCrashCount)); + } + public void resetGameState() { + try { + // Free up memory such that this works properly in case of an OutOfMemoryError + int originalMemoryReserveSize = -1; + try { // In case another mod actually deletes the memoryReserve field + if (memoryReserve != null) { + originalMemoryReserveSize = memoryReserve.length; + memoryReserve = new byte[0]; + } + } catch (Throwable ignored) {} + + StateManager.resetStates(); + + if (getNetHandler() != null) { + getNetHandler().getNetworkManager().closeChannel(new ChatComponentText("[BetterCrashes] Client crashed")); + } + loadWorld(null); + if (entityRenderer.isShaderActive()) { + entityRenderer.deactivateShader(); + } + field_152351_aB.clear(); // TODO: Figure out why this isn't necessary for vanilla disconnect + + if (originalMemoryReserveSize != -1) { + try { + memoryReserve = new byte[originalMemoryReserveSize]; + } catch (Throwable ignored) {} + } + System.gc(); + } catch (Throwable t) { + logger.error("Failed to reset state after a crash", t); + try { + StateManager.resetStates(); + } catch (Throwable ignored) {} + } + } + public void displayInitErrorScreen(CrashReport report) { + CrashUtils.outputReport(report); + try { + mcResourceManager = new SimpleReloadableResourceManager(metadataSerializer_); + renderEngine = new TextureManager(mcResourceManager); + mcResourceManager.registerReloadListener(renderEngine); + + mcLanguageManager = new LanguageManager(metadataSerializer_, gameSettings.language); + mcResourceManager.registerReloadListener(mcLanguageManager); + + refreshResources(); // TODO: Why is this necessary? + fontRenderer = new FontRenderer(gameSettings, new ResourceLocation("textures/font/ascii.png"), renderEngine, false); + mcResourceManager.registerReloadListener(fontRenderer); + + mcSoundHandler = new SoundHandler(mcResourceManager, gameSettings); + mcResourceManager.registerReloadListener(mcSoundHandler); + + running = true; + try { + //noinspection deprecation + SplashProgress.pause();// Disable the forge splash progress screen + } catch (Throwable ignored) {} + runGUILoop(new GuiInitErrorScreen(report)); + } catch (Throwable t) { + logger.error("An uncaught exception occured while displaying the init error screen, making normal report instead", t); + displayCrashReport(report); + System.exit(report.getFile() != null ? -1 : -2); + } + } + private void runGUILoop(GuiScreen screen) throws IOException { + displayGuiScreen(screen); + while (running && currentScreen != null && !(currentScreen instanceof GuiMainMenu) && !(Loader.isModLoaded("custommainmenu"))) { + if (Display.isCreated() && Display.isCloseRequested()) { + System.exit(0); + } + leftClickCounter = 10000; + currentScreen.handleInput(); + currentScreen.updateScreen(); + + GL11.glPushMatrix(); + GL11.glClear(16640); + framebufferMc.bindFramebuffer(true); + GL11.glEnable(GL11.GL_TEXTURE_2D); + + GL11.glViewport(0, 0, displayWidth, displayHeight); + + // EntityRenderer.setupOverlayRendering + ScaledResolution scaledResolution = new ScaledResolution((Minecraft) (Object) this,displayWidth,displayHeight); + GL11.glClear(256); + GL11.glMatrixMode(5889); + GL11.glLoadIdentity(); + GL11.glOrtho(0.0D, scaledResolution.getScaledWidth_double(), scaledResolution.getScaledHeight_double(), 0, 1000, 3000); + GL11.glMatrixMode(5888); + GL11.glLoadIdentity(); + GL11.glTranslatef(0, 0, -2000); + GL11.glClear(256); + + int width = scaledResolution.getScaledWidth(); + int height = scaledResolution.getScaledHeight(); + int mouseX = Mouse.getX() * width / displayWidth; + int mouseY = height - Mouse.getY() * height / displayHeight - 1; + currentScreen.drawScreen(mouseX, mouseY, 0); + + framebufferMc.unbindFramebuffer(); + GL11.glPopMatrix(); + + GL11.glPushMatrix(); + framebufferMc.framebufferRender(displayWidth, displayHeight); + GL11.glPopMatrix(); + + func_147120_f(); + Thread.yield(); + Display.sync(60); + checkGLError("BetterCrashes GUI Loop"); + } + } + + + + /** + * @author Runemoro + * @reason + */ + @Overwrite + public void displayCrashReport(CrashReport report) { + CrashUtils.outputReport(report); + } + +} + + + diff --git a/src/main/java/vfyjxf/bettercrashes/utils/CrashUtils.java b/src/main/java/vfyjxf/bettercrashes/utils/CrashUtils.java new file mode 100644 index 0000000..3454b66 --- /dev/null +++ b/src/main/java/vfyjxf/bettercrashes/utils/CrashUtils.java @@ -0,0 +1,57 @@ +package vfyjxf.bettercrashes.utils; + +import net.minecraft.client.Minecraft; +import net.minecraft.crash.CrashReport; +import vfyjxf.bettercrashes.BetterCrashes; + +import java.awt.*; +import java.io.File; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class CrashUtils { + + + public static void outputReport(CrashReport report) { + try { + if (report.getFile() == null) { + String reportName = "crash-"; + reportName += new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss").format(new Date()); + reportName += Minecraft.getMinecraft().func_152345_ab() ? "-client" : "-server"; + reportName += ".txt"; + + File reportsDir = isClient() ? new File(Minecraft.getMinecraft().mcDataDir, "crash-reports") : new File("crash-reports"); + File reportFile = new File(reportsDir, reportName); + + report.saveToFile(reportFile); + } + } catch (Throwable e) { + BetterCrashes.logger.fatal("Failed saving report", e); + } + + BetterCrashes.logger.fatal("Minecraft ran into a problem! " + (report.getFile() != null ? "Report saved to: " + report.getFile() : "Crash report could not be saved.") + + "\n" + report.getCompleteReport()); + } + + private static boolean isClient() { + try { + return Minecraft.getMinecraft() != null; + } catch (NoClassDefFoundError e) { + return false; + } + } + + public static void openCrashReport(CrashReport crashReport) throws IOException { + + if(!Desktop.isDesktopSupported()){ + BetterCrashes.logger.error("Desktop is not supported"); + return; + } + File report = crashReport.getFile(); + if(report.exists()){ + Desktop.getDesktop().open(report); + } + } + +} diff --git a/src/main/java/vfyjxf/bettercrashes/utils/GuiCrashScreen.java b/src/main/java/vfyjxf/bettercrashes/utils/GuiCrashScreen.java new file mode 100644 index 0000000..defc027 --- /dev/null +++ b/src/main/java/vfyjxf/bettercrashes/utils/GuiCrashScreen.java @@ -0,0 +1,55 @@ +package vfyjxf.bettercrashes.utils; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiMainMenu; +import net.minecraft.client.gui.GuiOptionButton; +import net.minecraft.client.resources.I18n; +import net.minecraft.crash.CrashReport; + +@SideOnly(Side.CLIENT) +public class GuiCrashScreen extends GuiProblemScreen{ + public GuiCrashScreen(CrashReport report) { + super(report); + } + @Override + public void initGui() { + super.initGui(); + GuiOptionButton mainMenuButton = new GuiOptionButton(0, width / 2 - 155, height / 4 + 120 + 12, I18n.format("bettercrashes.gui.toTitle")); + buttonList.add(mainMenuButton); + } + + @Override + protected void actionPerformed(GuiButton button) { + super.actionPerformed(button); + if (button.id == 0) { + mc.displayGuiScreen(new GuiMainMenu()); + } + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { // TODO: localize number of lines + drawDefaultBackground(); + drawCenteredString(fontRendererObj, I18n.format("bettercrashes.crashscreen.title"), width / 2, height / 4 - 40, 0xFFFFFF); + + int textColor = 0xD0D0D0; + int x = width / 2 - 155; + int y = height / 4; + + drawString(fontRendererObj, I18n.format("bettercrashes.crashscreen.summary"), x, y, textColor); + drawString(fontRendererObj, I18n.format("bettercrashes.crashscreen.paragraph1.line1"), x, y += 18, textColor); + + drawCenteredString(fontRendererObj, getModListString(), width / 2, y += 11, 0xE0E000); + + drawString(fontRendererObj, I18n.format("bettercrashes.crashscreen.paragraph2.line1"), x, y += 11, textColor); + + drawCenteredString(fontRendererObj, report.getFile() != null ? "\u00A7n" + report.getFile().getName() : I18n.format("vanillafix.crashscreen.reportSaveFailed"), width / 2, y += 11, 0x00FF00); + + drawString(fontRendererObj, I18n.format("bettercrashes.crashscreen.paragraph3.line1"), x, y += 12, textColor); + drawString(fontRendererObj, I18n.format("bettercrashes.crashscreen.paragraph3.line2"), x, y += 9, textColor); + drawString(fontRendererObj, I18n.format("bettercrashes.crashscreen.paragraph3.line3"), x, y += 9, textColor); + + super.drawScreen(mouseX, mouseY, partialTicks); + } +} diff --git a/src/main/java/vfyjxf/bettercrashes/utils/GuiInitErrorScreen.java b/src/main/java/vfyjxf/bettercrashes/utils/GuiInitErrorScreen.java new file mode 100644 index 0000000..3d5ea4d --- /dev/null +++ b/src/main/java/vfyjxf/bettercrashes/utils/GuiInitErrorScreen.java @@ -0,0 +1,52 @@ +package vfyjxf.bettercrashes.utils; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.resources.I18n; +import net.minecraft.crash.CrashReport; + +@SideOnly(Side.CLIENT) +public class GuiInitErrorScreen extends GuiProblemScreen{ + + public GuiInitErrorScreen(CrashReport report) { + super(report); + } + + @Override + public void initGui() { + mc.setIngameNotInFocus(); + buttonList.clear(); + buttonList.add(new GuiButton(1, width / 2 - 155, height / 4 + 120 + 12, 310, 20, I18n.format("bettercrashes.gui.openCrashReport"))); + } + + @Override + protected void actionPerformed(GuiButton button) { + super.actionPerformed(button); + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { // TODO: localize number of lines + drawDefaultBackground(); + drawCenteredString(fontRendererObj, I18n.format("bettercrashes.initerrorscreen.title"), width / 2, height / 4 - 40, 0xFFFFFF); + + int textColor = 0xD0D0D0; + int x = width / 2 - 155; + int y = height / 4; + + drawString(fontRendererObj, I18n.format("bettercrashes.initerrorscreen.summary"), x, y, textColor); + drawString(fontRendererObj, I18n.format("bettercrashes.crashscreen.paragraph1.line1"), x, y += 18, textColor); + + drawCenteredString(fontRendererObj, getModListString(), width / 2, y += 11, 0xE0E000); + + drawString(fontRendererObj, I18n.format("bettercrashes.crashscreen.paragraph2.line1"), x, y += 11, textColor); + + drawCenteredString(fontRendererObj, report.getFile() != null ? "\u00A7n" + report.getFile().getName() : I18n.format("vanillafix.crashscreen.reportSaveFailed"), width / 2, y += 11, 0x00FF00); + + drawString(fontRendererObj, I18n.format("bettercrashes.initerrorscreen.paragraph3.line1"), x, y += 12, textColor); + drawString(fontRendererObj, I18n.format("bettercrashes.initerrorscreen.paragraph3.line2"), x, y += 9, textColor); + drawString(fontRendererObj, I18n.format("bettercrashes.initerrorscreen.paragraph3.line3"), x, y += 9, textColor); + + super.drawScreen(mouseX, mouseY, partialTicks); + } +} diff --git a/src/main/java/vfyjxf/bettercrashes/utils/GuiProblemScreen.java b/src/main/java/vfyjxf/bettercrashes/utils/GuiProblemScreen.java new file mode 100644 index 0000000..7515c25 --- /dev/null +++ b/src/main/java/vfyjxf/bettercrashes/utils/GuiProblemScreen.java @@ -0,0 +1,70 @@ +package vfyjxf.bettercrashes.utils; + +import cpw.mods.fml.common.ModContainer; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.resources.I18n; +import net.minecraft.crash.CrashReport; +import org.apache.commons.lang3.StringUtils; +import vfyjxf.bettercrashes.BetterCrashes; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +@SideOnly(Side.CLIENT) +public abstract class GuiProblemScreen extends GuiScreen { + + protected final CrashReport report; + private String hasteLink = null; + private String modListString; + + public GuiProblemScreen(CrashReport report) { + this.report = report; + } + + @Override + public void initGui() { + mc.setIngameNotInFocus(); + buttonList.clear(); + buttonList.add(new GuiButton(1, width / 2 - 155 + 160, height / 4 + 120 + 12, 150, 20, I18n.format("bettercrashes.gui.openCrashReport"))); + } + + @Override + protected void actionPerformed(GuiButton button) { + if(button.id == 1){ + try { + CrashUtils.openCrashReport(report); + } catch (IOException e) { + BetterCrashes.logger.error("Can't open crashreoprt",e); + button.displayString = I18n.format("bettercrashes.gui.failed"); + button.enabled = false; + } + } + } + + @Override + protected void keyTyped(char typedChar, int keyCode) {} + + protected String getModListString() { + if (modListString == null) { + final Set suspectedMods = ((IPatchedCrashReport) report).getSuspectedMods(); + if (suspectedMods == null) { + return modListString = I18n.format("bettercrashes.crashscreen.identificationErrored"); + } + List modNames = new ArrayList<>(); + for (ModContainer mod : suspectedMods) { + modNames.add(mod.getName()); + } + if (modNames.isEmpty()) { + modListString = I18n.format("bettercrashes.crashscreen.unknownCause"); + } else { + modListString = StringUtils.join(modNames, ", "); + } + } + return modListString; + } +} diff --git a/src/main/java/vfyjxf/bettercrashes/utils/IPatchedCrashReport.java b/src/main/java/vfyjxf/bettercrashes/utils/IPatchedCrashReport.java new file mode 100644 index 0000000..d0d6501 --- /dev/null +++ b/src/main/java/vfyjxf/bettercrashes/utils/IPatchedCrashReport.java @@ -0,0 +1,9 @@ +package vfyjxf.bettercrashes.utils; + +import cpw.mods.fml.common.ModContainer; + +import java.util.Set; + +public interface IPatchedCrashReport { + Set getSuspectedMods(); +} diff --git a/src/main/java/vfyjxf/bettercrashes/utils/IPatchedMinecraft.java b/src/main/java/vfyjxf/bettercrashes/utils/IPatchedMinecraft.java new file mode 100644 index 0000000..acb0f61 --- /dev/null +++ b/src/main/java/vfyjxf/bettercrashes/utils/IPatchedMinecraft.java @@ -0,0 +1,9 @@ +package vfyjxf.bettercrashes.utils; + +import net.minecraft.crash.CrashReport; + +public interface IPatchedMinecraft { + boolean shouldCrashIntegratedServerNextTick(); + void showWarningScreen(CrashReport report); + void makeErrorNotification(CrashReport report); +} diff --git a/src/main/java/vfyjxf/bettercrashes/utils/ModIdentifier.java b/src/main/java/vfyjxf/bettercrashes/utils/ModIdentifier.java new file mode 100644 index 0000000..0282f68 --- /dev/null +++ b/src/main/java/vfyjxf/bettercrashes/utils/ModIdentifier.java @@ -0,0 +1,97 @@ +package vfyjxf.bettercrashes.utils; + +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.ModContainer; +import net.minecraft.launchwrapper.Launch; +import net.minecraft.launchwrapper.LaunchClassLoader; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Method; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.*; + +public final class ModIdentifier { + private static final Logger log = LogManager.getLogger(); + + public static Set identifyFromStacktrace(Throwable e) { + Map> modMap = makeModMap(); + + // Get the set of classes + HashSet classes = new LinkedHashSet<>(); + while (e != null) { + for (StackTraceElement element : e.getStackTrace()) { + classes.add(element.getClassName()); + } + e = e.getCause(); + } + + Set mods = new LinkedHashSet<>(); + for (String className : classes) { + Set classMods = identifyFromClass(className, modMap); + if (classMods != null) mods.addAll(classMods); + } + return mods; + } + + public static Set identifyFromClass(String className) { + return identifyFromClass(className, makeModMap()); + } + + private static Set identifyFromClass(String className, Map> modMap) { + // Skip identification for Mixin, one's mod copy of the library is shared with all other mods + if (className.startsWith("org.spongepowered.asm.mixin.")) return Collections.emptySet(); + + // Get the URL of the class + final String untrasformedName = untransformName(Launch.classLoader, className); + URL url = Launch.classLoader.getResource(untrasformedName.replace('.', '/') + ".class"); + log.debug(className + " = " + untrasformedName + " = " + url); + if (url == null) { + log.warn("Failed to identify " + className + " (untransformed name: " + untrasformedName + ")"); + return Collections.emptySet(); + } + + // Get the mod containing that class + try { + if (url.getProtocol().equals("jar")) url = new URL(url.getFile().substring(0, url.getFile().indexOf('!'))); + return modMap.get(new File(url.toURI()).getCanonicalFile()); + } catch (URISyntaxException | IOException e) { + throw new RuntimeException(e); + } + } + + private static Map> makeModMap() { + Map> modMap = new HashMap<>(); + for (ModContainer mod : Loader.instance().getModList()) { + Set currentMods = modMap.getOrDefault(mod.getSource(), new HashSet<>()); + currentMods.add(mod); + try { + modMap.put(mod.getSource().getCanonicalFile(), currentMods); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + try { + modMap.remove(Loader.instance().getMinecraftModContainer().getSource()); // Ignore minecraft jar (minecraft) + modMap.remove(Loader.instance().getIndexedModList().get("FML").getSource()); // Ignore forge jar (FML, forge) + } catch (NullPointerException ignored) { + // Workaround for https://github.com/MinecraftForge/MinecraftForge/issues/4919 + } + + return modMap; + } + + private static String untransformName(LaunchClassLoader launchClassLoader, String className) { + try { + Method untransformNameMethod = LaunchClassLoader.class.getDeclaredMethod("untransformName", String.class); + untransformNameMethod.setAccessible(true); + return (String) untransformNameMethod.invoke(launchClassLoader, className); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } + } +} diff --git a/src/main/java/vfyjxf/bettercrashes/utils/StacktraceDeobfuscator.java b/src/main/java/vfyjxf/bettercrashes/utils/StacktraceDeobfuscator.java new file mode 100644 index 0000000..12712c0 --- /dev/null +++ b/src/main/java/vfyjxf/bettercrashes/utils/StacktraceDeobfuscator.java @@ -0,0 +1,118 @@ +package vfyjxf.bettercrashes.utils; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.*; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +public final class StacktraceDeobfuscator { + private static final boolean DEBUG_IN_DEV = false; // Makes this MCP -> SRG for testing in dev. Don't forget to set to false when done! + private static HashMap srgMcpMethodMap = null; + + /** + * If the file does not exits, downloads latest method mappings and saves them to it. + * Initializes a HashMap between obfuscated and deobfuscated names from that file. + */ + public static void init(File mappings) { + if (srgMcpMethodMap != null) return; + + // Download the file if necessary + if (!mappings.exists()) { + HttpURLConnection connection = null; + try { + URL mappingsURL = new URL("http://export.mcpbot.bspk.rs/mcp_stable_nodoc/39-1.12/mcp_stable_nodoc-39-1.12.zip"); + connection = (HttpURLConnection) mappingsURL.openConnection(); + connection.setDoInput(true); + connection.connect(); + try (InputStream inputStream = connection.getInputStream()) { + ZipInputStream zipInputStream = new ZipInputStream(inputStream); + ZipEntry entry; + while ((entry = zipInputStream.getNextEntry()) != null) { + if (entry.getName().equals("methods.csv")) { + try (FileOutputStream out = new FileOutputStream(mappings)) { + byte[] buffer = new byte[2048]; + int len; + while ((len = zipInputStream.read(buffer)) > 0) { + out.write(buffer, 0, len); + } + } + break; + } + } + if (entry == null) { + throw new RuntimeException("Downloaded zip did not contain methods.csv"); + } + } + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + if (connection != null) connection.disconnect(); + } + } + + // Read the mapping + HashMap srgMcpMethodMap = new HashMap<>(); + try (Scanner scanner = new Scanner(mappings)) { + scanner.nextLine(); // Skip CSV header + while (scanner.hasNext()) { + String mappingLine = scanner.nextLine(); + int commaIndex = mappingLine.indexOf(','); + String srgName = mappingLine.substring(0, commaIndex); + String mcpName = mappingLine.substring(commaIndex + 1, commaIndex + 1 + mappingLine.substring(commaIndex + 1).indexOf(',')); + + //System.out.println(srgName + " <=> " + mcpName); + if (!DEBUG_IN_DEV) { + srgMcpMethodMap.put(srgName, mcpName); + } else { + srgMcpMethodMap.put(mcpName, srgName); + } + } + } catch (IOException e) { + throw new RuntimeException(e); + } + + // Set the map only if it's successful, to make sure that it's complete + StacktraceDeobfuscator.srgMcpMethodMap = srgMcpMethodMap; + } + + public static void deobfuscateThrowable(Throwable t) { + Deque queue = new ArrayDeque<>(); + queue.add(t); + while (!queue.isEmpty()) { + t = queue.remove(); + t.setStackTrace(deobfuscateStacktrace(t.getStackTrace())); + if (t.getCause() != null) queue.add(t.getCause()); + Collections.addAll(queue, t.getSuppressed()); + } + } + + public static StackTraceElement[] deobfuscateStacktrace(StackTraceElement[] stackTrace) { + int index = 0; + for (StackTraceElement el : stackTrace) { + stackTrace[index++] = new StackTraceElement(el.getClassName(), deobfuscateMethodName(el.getMethodName()), el.getFileName(), el.getLineNumber()); + } + return stackTrace; + } + + public static String deobfuscateMethodName(String srgName) { + if (srgMcpMethodMap == null) { + return srgName; // Not initialized + } + + String mcpName = srgMcpMethodMap.get(srgName); + // log.debug(srgName + " <=> " + mcpName != null ? mcpName : "?"); // Can't do this, it would be a recursive call to log appender + return mcpName != null ? mcpName : srgName; + } + + public static void main(String[] args) { + init(new File("methods.csv")); + for (Map.Entry entry : srgMcpMethodMap.entrySet()) { + System.out.println(entry.getKey() + " <=> " + entry.getValue()); + } + } +} diff --git a/src/main/java/vfyjxf/bettercrashes/utils/StateManager.java b/src/main/java/vfyjxf/bettercrashes/utils/StateManager.java new file mode 100644 index 0000000..5cc1f93 --- /dev/null +++ b/src/main/java/vfyjxf/bettercrashes/utils/StateManager.java @@ -0,0 +1,31 @@ +package vfyjxf.bettercrashes.utils; + +import java.lang.ref.WeakReference; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +public class StateManager { + public interface IResettable { + default void register() { + resettableRefs.add(new WeakReference<>(this)); + } + + void resetState(); + } + + // Use WeakReference to allow garbage collection, preventing memory leaks + private static Set> resettableRefs = new HashSet<>(); + + public static void resetStates() { + Iterator> iterator = resettableRefs.iterator(); + while (iterator.hasNext()) { + WeakReference ref = iterator.next(); + if (ref.get() != null) { + ref.get().resetState(); + } else { + iterator.remove(); + } + } + } +} diff --git a/src/main/resources/assets/bettercrashes/lang/eu_US.lang b/src/main/resources/assets/bettercrashes/lang/eu_US.lang new file mode 100644 index 0000000..1e6198a --- /dev/null +++ b/src/main/resources/assets/bettercrashes/lang/eu_US.lang @@ -0,0 +1,21 @@ +bettercrashes.gui.openCrashReport=Open CrashReport +bettercrashes.gui.failed=[Failed] +bettercrashes.crashscreen.identificationErrored=[Error identifying] +bettercrashes.crashscreen.unknownCause=Unknown +bettercrashes.gui.toTitle=Return to main menu + +bettercrashes.crashscreen.title=Minecraft crashed! +bettercrashes.crashscreen.summary=Minecraft ran into a problem and crashed. +bettercrashes.crashscreen.paragraph1.line1=The following mod(s) have been identified as potential causes: +bettercrashes.crashscreen.paragraph2.line1=report has been generated, and click the button below to open: +bettercrashes.crashscreen.paragraph3.line1=You're encouraged to send this report to the mod's author to help +bettercrashes.crashscreen.paragraph3.line2=them fix the issue. Since Since BetterCrashes is installed, you can keep +bettercrashes.crashscreen.paragraph3.line3=playing despite the crash. + +bettercrashes.initerrorscreen.title=Minecraft failed to start! +bettercrashes.initerrorscreen.summary=An error during startup prevented Minecraft from starting +bettercrashes.initerrorscreen.paragraph2.line1=report has been generated, and click the button below to open: +bettercrashes.initerrorscreen.paragraph3.line1=You're encouraged to send this report to the mod's author to help +bettercrashes.initerrorscreen.paragraph3.line2=them fix the issue. Since BetterCrashes is installed, you can keep +bettercrashes.initerrorscreen.paragraph3.line3=playing despite the crash. + diff --git a/src/main/resources/assets/bettercrashes/lang/zh_CN.lang b/src/main/resources/assets/bettercrashes/lang/zh_CN.lang new file mode 100644 index 0000000..cfef474 --- /dev/null +++ b/src/main/resources/assets/bettercrashes/lang/zh_CN.lang @@ -0,0 +1,21 @@ +bettercrashes.gui.openCrashReport=打开崩溃报告 +bettercrashes.gui.failed=[失败] +bettercrashes.crashscreen.identificationErrored=[鉴别错误] +bettercrashes.crashscreen.unknownCause=未知 +bettercrashes.gui.toTitle=回到主菜单 + +bettercrashes.crashscreen.title=Minecraft崩溃啦! +bettercrashes.crashscreen.summary=Minecraft遇到了一个问题并崩溃了。 +bettercrashes.crashscreen.paragraph1.line1=下列模组被认为可能是导致崩溃的原因: +bettercrashes.crashscreen.paragraph2.line1=一份报告已经生成,点击下方的按钮可以打开它: +bettercrashes.crashscreen.paragraph3.line1=我们建议您将此报告发送给模组的作者以帮助它们修复问题。 +bettercrashes.crashscreen.paragraph3.line2=由于安装了BetterCrashes,尽管发生了崩溃,你仍然可以继续进行游戏。 +bettercrashes.crashscreen.paragraph3.line3= + +bettercrashes.initerrorscreen.title=Minecraft未能启动! +bettercrashes.initerrorscreen.summary=启动过程中的一个错误阻止了Minecraft的启动 +bettercrashes.initerrorscreen.paragraph2.line1=一份报告已经生成,点击下方的按钮可以打开它: +bettercrashes.initerrorscreen.paragraph3.line1=我们建议您将此报告发送给模组的作者以帮助它们修复问题。 +bettercrashes.initerrorscreen.paragraph3.line2=由于安装了BetterCrashes,尽管发生了崩溃,你仍然可以继续进行游戏。 +bettercrashes.initerrorscreen.paragraph3.line3= + diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info new file mode 100644 index 0000000..f4ff2a6 --- /dev/null +++ b/src/main/resources/mcmod.info @@ -0,0 +1,14 @@ +[{ + "modid": "${mod_id}", + "name": "${mod_name}", + "description": "${mod_description}", + "version": "${mod_version}", + "mcversion": "${mc_version}", + "url": "", + "updateUrl": "", + "authorList": ["${mod_author}"], + "credits": "", + "logoFile": "${mod_icon}", + "screenshots": [], + "dependencies": [] +}] \ No newline at end of file