Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(legacy): Crash Report dialog #4968

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/net/ccbluex/liquidbounce/LiquidBounce.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ object LiquidBounce {
const val CLIENT_AUTHOR = "CCBlueX"
const val CLIENT_CLOUD = "https://cloud.liquidbounce.net/LiquidBounce"
const val CLIENT_WEBSITE = "liquidbounce.net"
const val CLIENT_GITHUB = "https://github.com/CCBlueX/LiquidBounce"

const val MINECRAFT_VERSION = "1.8.9"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.ccbluex.liquidbounce.utils.attack.CPSCounter;
import net.ccbluex.liquidbounce.utils.client.ClientUtils;
import net.ccbluex.liquidbounce.utils.inventory.SilentHotbar;
import net.ccbluex.liquidbounce.utils.io.MiscUtils;
import net.ccbluex.liquidbounce.utils.render.IconUtils;
import net.ccbluex.liquidbounce.utils.render.MiniMapRegister;
import net.ccbluex.liquidbounce.utils.render.RenderUtils;
Expand All @@ -34,6 +35,7 @@
import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.crash.CrashReport;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
Expand All @@ -52,6 +54,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.nio.ByteBuffer;
import java.time.LocalDateTime;
import java.util.Queue;

import static net.ccbluex.liquidbounce.utils.client.MinecraftInstance.mc;
Expand Down Expand Up @@ -221,6 +224,16 @@ private void shutdown(CallbackInfo callbackInfo) {
LiquidBounce.INSTANCE.stopClient();
}

@Inject(method = "displayCrashReport", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/FMLCommonHandler;instance()Lnet/minecraftforge/fml/common/FMLCommonHandler;"))
private void injectDisplayCrashReport(CrashReport crashReport, CallbackInfo callbackInfo) {
final StringBuilder crashInfo = new StringBuilder(LiquidBounce.CLIENT_NAME).append(" crash info\n");
crashInfo.append("Client version: ").append(LiquidBounce.INSTANCE.getClientVersionText()).append(' ').append(LiquidBounce.INSTANCE.getClientCommit()).append('\n');
crashInfo.append("Time: ").append(LocalDateTime.now()).append('\n');
crashInfo.append('\n');
MiscUtils.showErrorPopup(crashReport.getCrashCause(), "Game crashed! ", crashInfo.toString());
MiscUtils.showURL(LiquidBounce.CLIENT_GITHUB + "/issues");
}

@Inject(method = "clickMouse", at = @At("HEAD"))
private void clickMouse(CallbackInfo callbackInfo) {
if (AutoClicker.INSTANCE.handleEvents()) {
Expand Down
45 changes: 40 additions & 5 deletions src/main/java/net/ccbluex/liquidbounce/utils/io/MiscUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,54 @@ package net.ccbluex.liquidbounce.utils.io

import net.ccbluex.liquidbounce.utils.client.MinecraftInstance
import java.awt.Desktop
import java.awt.Font
import java.io.File
import java.io.IOException
import java.net.URI
import java.net.URISyntaxException
import javax.swing.JFileChooser
import javax.swing.JFrame
import javax.swing.JOptionPane
import java.time.LocalDateTime
import javax.swing.*
import javax.swing.filechooser.FileFilter

object MiscUtils : MinecraftInstance() {
fun showErrorPopup(title: String, message: String) =

private fun JTextArea.adjustTextAreaSize() {
val fontMetrics = getFontMetrics(font)

val lineSequence = text.lineSequence()
val lines = lineSequence.count()
val maxLineWidth = lineSequence.maxOfOrNull { fontMetrics.stringWidth(it) } ?: 0
val columns = maxLineWidth / fontMetrics.charWidth('m')

this.rows = lines + 1
this.columns = columns + 1
}

@JvmStatic
fun showErrorPopup(title: String, message: Any) =
JOptionPane.showMessageDialog(null, message, title, JOptionPane.ERROR_MESSAGE)

fun Throwable.showErrorPopup() = showErrorPopup(javaClass.simpleName, localizedMessage)
@JvmStatic
fun Throwable.showErrorPopup(
titlePrefix: String = "Exception occurred: ",
extraContent: String = LocalDateTime.now().toString() + '\n'
) {
val title = titlePrefix + javaClass.simpleName

val content = extraContent + "--- Stacktrace ---\n" + stackTraceToString()

val textArea = JTextArea(content).apply {
isEditable = false
lineWrap = true
wrapStyleWord = true
font = Font("Consolas", Font.PLAIN, 12)
adjustTextAreaSize()
}

showErrorPopup(title, textArea)
}

@JvmStatic
fun showURL(url: String) =
try {
Desktop.getDesktop().browse(URI(url))
Expand All @@ -31,6 +64,7 @@ object MiscUtils : MinecraftInstance() {
e.showErrorPopup()
}

@JvmStatic
fun openFileChooser(fileFiler: FileFilter? = null): File? {
if (mc.isFullScreen) mc.toggleFullscreen()

Expand All @@ -49,6 +83,7 @@ object MiscUtils : MinecraftInstance() {
return if (action == JFileChooser.APPROVE_OPTION) fileChooser.selectedFile else null
}

@JvmStatic
fun saveFileChooser(fileFiler: FileFilter? = null): File? {
if (mc.isFullScreen) mc.toggleFullscreen()

Expand Down
Loading