Skip to content

Commit b98738e

Browse files
committed
Crash report dynamic mapping
1 parent 48da4f7 commit b98738e

File tree

3 files changed

+153
-2
lines changed

3 files changed

+153
-2
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.mixin;
19+
20+
import com.lambda.Lambda;
21+
import com.lambda.util.DynamicException;
22+
import net.minecraft.client.MinecraftClient;
23+
import net.minecraft.util.Util;
24+
import net.minecraft.util.crash.CrashReport;
25+
import org.spongepowered.asm.mixin.Final;
26+
import org.spongepowered.asm.mixin.Mixin;
27+
import org.spongepowered.asm.mixin.Mutable;
28+
import org.spongepowered.asm.mixin.Shadow;
29+
import org.spongepowered.asm.mixin.injection.At;
30+
import org.spongepowered.asm.mixin.injection.Inject;
31+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
32+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
33+
34+
// Modify the crash report behavior for dynamic remapping and Easter egg
35+
@Mixin(CrashReport.class)
36+
public class CrashReportMixin {
37+
@Mutable
38+
@Shadow @Final private Throwable cause;
39+
40+
@Inject(method = "<init>(Ljava/lang/String;Ljava/lang/Throwable;)V", at = @At("TAIL"))
41+
void injectConstructor(String message, Throwable cause, CallbackInfo ci) {
42+
if (!Lambda.INSTANCE.isDebug() && MinecraftClient.getInstance() != null) {
43+
this.cause = new DynamicException(cause);
44+
}
45+
}
46+
47+
@Inject(method = "generateWittyComment()Ljava/lang/String;", at = @At("HEAD"), cancellable = true)
48+
private static void generateWittyComment(CallbackInfoReturnable<String> cir) {
49+
String[] strings = new String[]{
50+
"Who set us up the TNT?",
51+
"Everything's going to plan. No, really, that was supposed to happen.",
52+
"Uh... Did I do that?",
53+
"Oops.",
54+
"Why did you do that?",
55+
"I feel sad now :(",
56+
"My bad.",
57+
"I'm sorry, Dave.",
58+
"I let you down. Sorry :(",
59+
"On the bright side, I bought you a teddy bear!",
60+
"Daisy, daisy...",
61+
"Oh - I know what I did wrong!",
62+
"Hey, that tickles! Hehehe!",
63+
"I blame Dinnerbone.",
64+
"You should try our sister game, Minceraft!",
65+
"Don't be sad. I'll do better next time, I promise!",
66+
"Don't be sad, have a hug! <3",
67+
"I just don't know what went wrong :(",
68+
"Shall we play a game?",
69+
"Quite honestly, I wouldn't worry myself about that.",
70+
"I bet Cylons wouldn't have this problem.",
71+
"Sorry :(",
72+
"Surprise! Haha. Well, this is awkward.",
73+
"Would you like a cupcake?",
74+
"Hi. I'm Minecraft, and I'm a crashaholic.",
75+
"Ooh. Shiny.",
76+
"This doesn't make any sense!",
77+
"Why is it breaking :(",
78+
"Don't do that.",
79+
"Ouch. That hurt :(",
80+
"You're mean.",
81+
"This is a token for 1 free hug. Redeem at your nearest Mojangsta: [~~HUG~~]",
82+
"There are four lights!",
83+
"But it works on my machine.",
84+
"Popbob was here.",
85+
"The oldest anarchy server in Minecraft."
86+
};
87+
88+
try {
89+
cir.setReturnValue(strings[(int)(Util.getMeasuringTimeNano() % (long)strings.length)]);
90+
} catch (Throwable var2) {
91+
cir.setReturnValue("Witty comment unavailable :(");
92+
}
93+
}
94+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.util
19+
20+
import com.lambda.util.DynamicReflectionSerializer.remappedName
21+
import java.io.PrintStream
22+
import java.io.PrintWriter
23+
24+
class DynamicException(original: Throwable) : Throwable(original) {
25+
private val remappedStackTrace = original.stackTrace.remapClassNames()
26+
27+
init {
28+
stackTrace = remappedStackTrace
29+
}
30+
31+
private fun Array<StackTraceElement>.remapClassNames() =
32+
map { element ->
33+
StackTraceElement(
34+
element.className.remappedName,
35+
element.methodName.remappedName,
36+
element.fileName,
37+
element.lineNumber
38+
)
39+
}.toTypedArray()
40+
41+
override fun printStackTrace(s: PrintStream) {
42+
s.println(this)
43+
remappedStackTrace.forEach { element ->
44+
s.println("\tat $element")
45+
}
46+
}
47+
48+
override fun printStackTrace(s: PrintWriter) {
49+
s.println(this)
50+
remappedStackTrace.forEach { element ->
51+
s.println("\tat $element")
52+
}
53+
}
54+
55+
override fun toString(): String = localizedMessage
56+
}

common/src/main/resources/lambda.mixins.common.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
"render.BackgroundRendererMixin",
3030
"render.BlockRenderManagerMixin",
3131
"render.CameraMixin",
32-
"render.ChatHudMixin",
3332
"render.CapeFeatureRendererMixin",
33+
"render.ChatHudMixin",
3434
"render.ChatInputSuggestorMixin",
3535
"render.ChatScreenMixin",
3636
"render.DebugHudMixin",
@@ -55,7 +55,8 @@
5555
"world.ClientChunkManagerMixin",
5656
"world.ClientWorldMixin",
5757
"world.StructureTemplateMixin",
58-
"world.WorldMixin"
58+
"world.WorldMixin",
59+
"CrashReportMixin"
5960
],
6061
"injectors": {
6162
"defaultRequire": 1

0 commit comments

Comments
 (0)