|
| 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.module.Module; |
| 22 | +import com.lambda.module.ModuleRegistry; |
| 23 | +import com.lambda.util.DynamicException; |
| 24 | +import net.minecraft.client.MinecraftClient; |
| 25 | +import net.minecraft.util.Util; |
| 26 | +import net.minecraft.util.crash.CrashReport; |
| 27 | +import org.spongepowered.asm.mixin.Final; |
| 28 | +import org.spongepowered.asm.mixin.Mixin; |
| 29 | +import org.spongepowered.asm.mixin.Mutable; |
| 30 | +import org.spongepowered.asm.mixin.Shadow; |
| 31 | +import org.spongepowered.asm.mixin.injection.At; |
| 32 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 33 | +import org.spongepowered.asm.mixin.injection.Redirect; |
| 34 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 35 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; |
| 36 | + |
| 37 | +// Modify the crash report behavior for dynamic remapping, Easter egg and github issue link |
| 38 | +@Mixin(CrashReport.class) |
| 39 | +public class CrashReportMixin { |
| 40 | + @Mutable |
| 41 | + @Shadow @Final private Throwable cause; |
| 42 | + |
| 43 | + @Inject(method = "<init>(Ljava/lang/String;Ljava/lang/Throwable;)V", at = @At("TAIL")) |
| 44 | + void injectConstructor(String message, Throwable cause, CallbackInfo ci) { |
| 45 | + if (!Lambda.INSTANCE.isDebug() && MinecraftClient.getInstance() != null) { |
| 46 | + this.cause = new DynamicException(cause); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + @Redirect(method = "asString()Ljava/lang/String;", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/crash/CrashReport;addStackTrace(Ljava/lang/StringBuilder;)V")) |
| 51 | + void injectString(CrashReport instance, StringBuilder stringBuilder) { |
| 52 | + stringBuilder.append("If this issue is related to Lambda, check if other users have experienced this too, or create a new issue at https://github.com/lambda-client/lambda/issues.\n\n"); |
| 53 | + |
| 54 | + if (MinecraftClient.getInstance() != null) { |
| 55 | + stringBuilder.append("Enabled modules:\n"); |
| 56 | + |
| 57 | + ModuleRegistry.INSTANCE.getModules() |
| 58 | + .stream().filter(Module::isEnabled) |
| 59 | + .forEach(m -> stringBuilder.append("\t").append(m.getName()).append("\n")); |
| 60 | + } |
| 61 | + |
| 62 | + stringBuilder.append("\n"); |
| 63 | + stringBuilder.append("-".repeat(43)); |
| 64 | + stringBuilder.append("\n\n"); |
| 65 | + |
| 66 | + instance.addStackTrace(stringBuilder); |
| 67 | + } |
| 68 | + |
| 69 | + @Inject(method = "generateWittyComment()Ljava/lang/String;", at = @At("HEAD"), cancellable = true) |
| 70 | + private static void generateWittyComment(CallbackInfoReturnable<String> cir) { |
| 71 | + String[] strings = new String[]{"Who set us up the TNT?", "Everything's going to plan. No, really, that was supposed to happen.", "Uh... Did I do that?", "Oops.", "Why did you do that?", "I feel sad now :(", "My bad.", "I'm sorry, Dave.", "I let you down. Sorry :(", "On the bright side, I bought you a teddy bear!", "Daisy, daisy...", "Oh - I know what I did wrong!", "Hey, that tickles! Hehehe!", "I blame Dinnerbone.", "You should try our sister game, Minceraft!", "Don't be sad. I'll do better next time, I promise!", "Don't be sad, have a hug! <3", "I just don't know what went wrong :(", "Shall we play a game?", "Quite honestly, I wouldn't worry myself about that.", "I bet Cylons wouldn't have this problem.", "Sorry :(", "Surprise! Haha. Well, this is awkward.", "Would you like a cupcake?", "Hi. I'm Minecraft, and I'm a crashaholic.", "Ooh. Shiny.", "This doesn't make any sense!", "Why is it breaking :(", "Don't do that.", "Ouch. That hurt :(", "You're mean.", "This is a token for 1 free hug. Redeem at your nearest Mojangsta: [~~HUG~~]", "There are four lights!", "But it works on my machine.", "Popbob was here.", "The oldest anarchy server in Minecraft.", "Better luck next time..", "Fatal error occurred user is too based.", "Running premium software on a potato is not advised", "I don't know, ask that kilab guy", "Ah shit, here we go again.", "I will uhh, fix that sometime.", "Not a bug, a feature!", "You should try out Lambda on Windows XP.", "Blade did that."}; |
| 72 | + |
| 73 | + try { |
| 74 | + cir.setReturnValue(strings[(int)(Util.getMeasuringTimeNano() % (long)strings.length)]); |
| 75 | + } catch (Throwable var2) { |
| 76 | + cir.setReturnValue("Witty comment unavailable :("); |
| 77 | + } |
| 78 | + } |
| 79 | +} |
0 commit comments