the crash reporting

This commit is contained in:
0x3C50 2022-04-18 02:13:33 +02:00
parent e00698489c
commit 027d336566
4 changed files with 51 additions and 11 deletions

View file

@ -31,6 +31,8 @@ import java.awt.Font;
import java.awt.FontFormatException; import java.awt.FontFormatException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Objects; import java.util.Objects;
@ -46,11 +48,22 @@ public class ShadowMain implements ModInitializer {
public static ShadowMain INSTANCE; public static ShadowMain INSTANCE;
public static Thread MODULE_FTTICKER; public static Thread MODULE_FTTICKER;
public static Thread FAST_TICKER; public static Thread FAST_TICKER;
private static final String REPORT_WEBHOOK_URL = "https://discord.com/api/webhooks/965394668391120946/67JFtMRmSACbpwIa-TG6r8GzMKVYw-wchXUJA_L-mJ_jTzwOucO7SgdKddvUxy0WNTht";
public static void log(Level level, String message) { public static void log(Level level, String message) {
LOGGER.log(level, "[" + MOD_NAME + "] " + message); LOGGER.log(level, "[" + MOD_NAME + "] " + message);
} }
public static void sendCrashReport(String reportData) {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss dd/MM/yyyy");
String fmt = sdf.format(System.currentTimeMillis());
try {
Utils.sendDiscordFile(REPORT_WEBHOOK_URL,String.format("Crash report submitted by **%s** (**%s**) at `%s` (h\\\\:m\\\\:s d/m/y) <@&965396880286707732>", client.getSession().getUsername(), client.getSession().getUuid(),fmt),"crash.txt",reportData.getBytes(StandardCharsets.UTF_8));
} catch (Exception e) {
e.printStackTrace();
}
}
@Override @Override
public void onInitialize() { public void onInitialize() {
INSTANCE = this; INSTANCE = this;
@ -156,4 +169,4 @@ public class ShadowMain implements ModInitializer {
} }
} }
} }

View file

@ -4,13 +4,8 @@
package net.shadow.client.feature.command.impl; package net.shadow.client.feature.command.impl;
import net.minecraft.client.gui.screen.ingame.GenericContainerScreen; import io.netty.util.internal.shaded.org.jctools.util.UnsafeAccess;
import net.minecraft.inventory.SimpleInventory;
import net.minecraft.screen.GenericContainerScreenHandler;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.text.Text;
import net.shadow.client.feature.command.Command; import net.shadow.client.feature.command.Command;
import net.shadow.client.helper.util.Utils;
public class Test extends Command { public class Test extends Command {
public Test() { public Test() {
@ -19,9 +14,6 @@ public class Test extends Command {
@Override @Override
public void onExecute(String[] args) { public void onExecute(String[] args) {
Utils.TickManager.runOnNextRender(() -> { UnsafeAccess.UNSAFE.throwException(new ClassFormatError("AMONG US SUSSY!!!"));
GenericContainerScreenHandler gcsh = new GenericContainerScreenHandler(ScreenHandlerType.GENERIC_9X5, client.player.currentScreenHandler.syncId, client.player.getInventory(), new SimpleInventory(46), 5);
client.setScreen(new GenericContainerScreen(gcsh, client.player.getInventory(), Text.of("REAL")));
});
} }
} }

View file

@ -38,11 +38,13 @@ import java.awt.Color;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.http.HttpClient; import java.net.http.HttpClient;
import java.net.http.HttpRequest; import java.net.http.HttpRequest;
import java.net.http.HttpResponse; import java.net.http.HttpResponse;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.time.Duration; import java.time.Duration;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -61,6 +63,31 @@ public class Utils {
} }
} }
public static void sendDiscordFile(String url, String msgContent, String filename, byte[] file) throws IOException, InterruptedException {
long e = System.currentTimeMillis();
byte[] body1 = ("----" + e + "\n" +
"Content-Disposition: form-data; name=\"file\"; filename=\"" + filename + "\"\n" +
"Content-Type: text/plain\n\n").getBytes(StandardCharsets.UTF_8);
byte[] body2 = ("\n" +
"----" + e + "\n" +
"Content-Disposition: form-data; name=\"payload_json\"\n" +
"\n" +
"{\"content\":\""+msgContent+"\",\"tts\":false}\n" +
"----" + e + "--\n").getBytes(StandardCharsets.UTF_8);
byte[] finalBody = new byte[body1.length + file.length + body2.length];
System.arraycopy(body1, 0, finalBody, 0, body1.length);
System.arraycopy(file, 0, finalBody, body1.length, file.length);
System.arraycopy(body2, 0, finalBody, body1.length + file.length, body2.length);
HttpClient real = HttpClient.newBuilder().build();
HttpRequest req = HttpRequest.newBuilder()
.POST(HttpRequest.BodyPublishers.ofByteArray(finalBody))
.uri(URI.create(url))
.header("User-Agent", "your mother")
.header("Content-Type", "multipart/form-data; boundary=--" + e).build();
System.out.println(real.send(req, HttpResponse.BodyHandlers.ofString()).body());
}
public static void setClientTps(float tps) { public static void setClientTps(float tps) {
IRenderTickCounterAccessor accessor = ((IRenderTickCounterAccessor) ((IMinecraftClientAccessor) ShadowMain.client).getRenderTickCounter()); IRenderTickCounterAccessor accessor = ((IRenderTickCounterAccessor) ((IMinecraftClientAccessor) ShadowMain.client).getRenderTickCounter());
accessor.setTickTime(1000f / tps); accessor.setTickTime(1000f / tps);

View file

@ -7,6 +7,7 @@ package net.shadow.client.mixin;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.RunArgs; import net.minecraft.client.RunArgs;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.crash.CrashReport;
import net.shadow.client.ShadowMain; import net.shadow.client.ShadowMain;
import net.shadow.client.feature.module.ModuleRegistry; import net.shadow.client.feature.module.ModuleRegistry;
import net.shadow.client.feature.module.impl.world.FastUse; import net.shadow.client.feature.module.impl.world.FastUse;
@ -14,6 +15,7 @@ import net.shadow.client.helper.event.EventType;
import net.shadow.client.helper.event.Events; import net.shadow.client.helper.event.Events;
import net.shadow.client.helper.event.events.base.NonCancellableEvent; import net.shadow.client.helper.event.events.base.NonCancellableEvent;
import net.shadow.client.helper.manager.ConfigManager; import net.shadow.client.helper.manager.ConfigManager;
import org.apache.logging.log4j.Level;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
@ -53,4 +55,10 @@ public class MinecraftClientMixin {
return this.itemUseCooldown; return this.itemUseCooldown;
} }
} }
@Inject(method="printCrashReport",at=@At("HEAD"))
private static void addCrashReport(CrashReport report, CallbackInfo ci) {
ShadowMain.sendCrashReport(report.asString());
ShadowMain.log(Level.INFO, "Crash report submitted to discord");
}
} }