Skip to content

Commit f899aec

Browse files
committed
dont close world when crashing
stacktrace deobfuscator show skyclient discord url in crash screen if using skyclient
1 parent 612df00 commit f899aec

File tree

16 files changed

+587
-57
lines changed

16 files changed

+587
-57
lines changed

build.gradle

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,21 @@ plugins {
77
id "net.kyori.blossom" version "1.3.0"
88
}
99

10-
version = "1.2.0"
10+
version = "1.3.0"
1111
group = "cc.woverflow"
1212
archivesBaseName = "CrashPatch"
1313

1414
blossom {
1515
replaceToken("@VERSION@", project.version, "src/main/kotlin/cc/woverflow/crashpatch/CrashPatch.kt")
1616
}
1717

18+
compileKotlin {
19+
kotlinOptions {
20+
jvmTarget = "1.8"
21+
freeCompilerArgs += "-Xjvm-default=all"
22+
}
23+
}
24+
1825
minecraft {
1926
version = "1.8.9-11.15.1.2318-1.8.9"
2027
runDir = "run"
@@ -57,7 +64,9 @@ processResources {
5764
"version" : project.version
5865
)
5966
}
67+
rename '(.+_at.cfg)', 'META-INF/$1'
6068
}
69+
6170
jar {
6271
manifest.attributes(
6372
"ModSide": "CLIENT",
@@ -113,7 +122,9 @@ reobf {
113122
}
114123

115124
sourceSets {
125+
dummy
116126
main {
127+
compileClasspath += dummy.output
117128
ext.refMap = "mixin.crashpatch.refmap.json"
118129
output.resourcesDir = file("${buildDir}/classes/java/main")
119130
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package gg.essential.util.crash;
2+
3+
public abstract class StacktraceDeobfuscator {
4+
public static StacktraceDeobfuscator get() {
5+
throw new AssertionError();
6+
}
7+
8+
public abstract void deobfuscateThrowable(Throwable t);
9+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package cc.woverflow.crashpatch.hooks;
2+
3+
public interface MinecraftHook {
4+
boolean hasRecoveredFromCrash();
5+
}

src/main/java/cc/woverflow/crashpatch/mixin/MixinCrashReport.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public class MixinCrashReport implements CrashReportHook {
2222
@Shadow
2323
@Final
2424
private Throwable cause;
25-
2625
private String crashpatch$suspectedMod;
2726

2827
@Override
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
package cc.woverflow.crashpatch.mixin;
2+
3+
import cc.woverflow.crashpatch.CrashPatch;
4+
import cc.woverflow.crashpatch.hooks.MinecraftHook;
5+
import gg.essential.universal.ChatColor;
6+
import gg.essential.universal.UDesktop;
7+
import net.minecraft.client.gui.FontRenderer;
8+
import net.minecraft.client.gui.GuiScreen;
9+
import net.minecraft.client.multiplayer.GuiConnecting;
10+
import org.spongepowered.asm.mixin.Mixin;
11+
import org.spongepowered.asm.mixin.injection.At;
12+
import org.spongepowered.asm.mixin.injection.Inject;
13+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
14+
15+
import java.awt.*;
16+
import java.io.IOException;
17+
import java.net.URI;
18+
19+
@Mixin(GuiConnecting.class)
20+
public class MixinGuiConnecting extends GuiScreen {
21+
22+
@Inject(method = "drawScreen", at = @At("TAIL"))
23+
private void drawWarningText(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) {
24+
if (((MinecraftHook) mc).hasRecoveredFromCrash()) {
25+
drawSplitCenteredString(getText(), width / 2, 5, Color.WHITE.getRGB());
26+
}
27+
}
28+
29+
private String getText() {
30+
return ChatColor.RED + "If Minecraft is stuck on this screen, please force close the game" + (CrashPatch.INSTANCE.isSkyclient() ? " and go to https://discord.gg/eh7tNFezct for support" : "") + ".";
31+
}
32+
33+
@Override
34+
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
35+
super.mouseClicked(mouseX, mouseY, mouseButton);
36+
if (((MinecraftHook) mc).hasRecoveredFromCrash()) {
37+
if (mouseButton == 0) {
38+
String[] list = wrapFormattedStringToWidth(getText(), width).split("\n");
39+
int width = -1;
40+
for (String text : list) {
41+
width = Math.max(width, fontRendererObj.getStringWidth(text));
42+
}
43+
int left = (this.width / 2) - width / 2;
44+
if ((width == -1 || (left < mouseX && left + width > mouseX)) && (mouseY > 5 && mouseY < 15 + ((list.length - 1) * (fontRendererObj.FONT_HEIGHT + 2)))) {
45+
UDesktop.browse(URI.create("https://discord.gg/eh7tNFezct"));
46+
}
47+
}
48+
}
49+
}
50+
51+
public void drawSplitCenteredString(String text, int x, int y, int color) {
52+
for (String line : wrapFormattedStringToWidth(text, width).split("\n")) {
53+
drawCenteredString(fontRendererObj, line, x, y, color);
54+
y += fontRendererObj.FONT_HEIGHT + 2;
55+
}
56+
}
57+
58+
public String wrapFormattedStringToWidth(String str, int wrapWidth)
59+
{
60+
int i = this.sizeStringToWidth(str, wrapWidth);
61+
62+
if (str.length() <= i)
63+
{
64+
return str;
65+
}
66+
else
67+
{
68+
String s = str.substring(0, i);
69+
char c0 = str.charAt(i);
70+
boolean flag = c0 == 32 || c0 == 10;
71+
String s1 = FontRenderer.getFormatFromString(s) + str.substring(i + (flag ? 1 : 0));
72+
return s + "\n" + this.wrapFormattedStringToWidth(s1, wrapWidth);
73+
}
74+
}
75+
76+
private int sizeStringToWidth(String str, int wrapWidth)
77+
{
78+
int i = str.length();
79+
int j = 0;
80+
int k = 0;
81+
int l = -1;
82+
83+
for (boolean flag = false; k < i; ++k)
84+
{
85+
char c0 = str.charAt(k);
86+
87+
switch (c0)
88+
{
89+
case '\n':
90+
--k;
91+
break;
92+
case ' ':
93+
l = k;
94+
default:
95+
j += fontRendererObj.getCharWidth(c0);
96+
97+
if (flag)
98+
{
99+
++j;
100+
}
101+
102+
break;
103+
case '\u00a7':
104+
105+
if (k < i - 1)
106+
{
107+
++k;
108+
char c1 = str.charAt(k);
109+
110+
if (c1 != 108 && c1 != 76)
111+
{
112+
if (c1 == 114 || c1 == 82 || isFormatColor(c1))
113+
{
114+
flag = false;
115+
}
116+
}
117+
else
118+
{
119+
flag = true;
120+
}
121+
}
122+
}
123+
124+
if (c0 == 10)
125+
{
126+
++k;
127+
l = k;
128+
break;
129+
}
130+
131+
if (j > wrapWidth)
132+
{
133+
break;
134+
}
135+
}
136+
137+
return k != i && l != -1 && l < k ? l : k;
138+
}
139+
140+
private static boolean isFormatColor(char colorChar)
141+
{
142+
return colorChar >= 48 && colorChar <= 57 || colorChar >= 97 && colorChar <= 102 || colorChar >= 65 && colorChar <= 70;
143+
}
144+
}

0 commit comments

Comments
 (0)