Skip to content

Commit

Permalink
Major cleanup, crash scans TBD
Browse files Browse the repository at this point in the history
  • Loading branch information
Deftu committed Dec 11, 2024
1 parent 6875e81 commit 1f53734
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 566 deletions.
4 changes: 3 additions & 1 deletion root.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ plugins {
}

preprocess {
"1.8.9-forge"(10809, "srg") {}
"1.8.9-forge"(10809, "srg") {
"1.8.9-fabric"(10809, "yarn") {}
}
}
3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ rootProject.buildFileName = "root.gradle.kts"

// Adds all of our build target versions to the classpath if we need to add version-specific code.
listOf(
"1.8.9-forge"
"1.8.9-forge",
"1.8.9-fabric"
).forEach { version ->
include(":$version")
project(":$version").apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.multiplayer.GuiConnecting;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -23,11 +24,12 @@ public class MixinGuiConnecting extends GuiScreen {
@Inject(method = "drawScreen", at = @At("TAIL"))
private void drawWarningText(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) {
if (((MinecraftHook) Minecraft.getMinecraft()).hasRecoveredFromCrash()) {
drawSplitCenteredString(getText(), width / 2, 5, Color.WHITE.getRGB());
crashpatch$drawSplitCenteredString(crashpatch$getText(), width / 2, 5, Color.WHITE.getRGB());
}
}

private String getText() {
@Unique
private String crashpatch$getText() {
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" : "") + ".";
}

Expand All @@ -36,7 +38,7 @@ protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOEx
super.mouseClicked(mouseX, mouseY, mouseButton);
if (((MinecraftHook) Minecraft.getMinecraft()).hasRecoveredFromCrash()) {
if (mouseButton == 0) {
String[] list = wrapFormattedStringToWidth(getText(), width).split("\n");
String[] list = crashpatch$wrapFormattedStringToWidth(crashpatch$getText(), width).split("\n");
int width = -1;
for (String text : list) {
width = Math.max(width, fontRendererObj.getStringWidth(text));
Expand All @@ -49,44 +51,40 @@ protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOEx
}
}

public void drawSplitCenteredString(String text, int x, int y, int color) {
for (String line : wrapFormattedStringToWidth(text, width).split("\n")) {
@Unique
public void crashpatch$drawSplitCenteredString(String text, int x, int y, int color) {
for (String line : crashpatch$wrapFormattedStringToWidth(text, width).split("\n")) {
drawCenteredString(fontRendererObj, line, x, y, color);
y += fontRendererObj.FONT_HEIGHT + 2;
}
}

public String wrapFormattedStringToWidth(String str, int wrapWidth)
{
int i = this.sizeStringToWidth(str, wrapWidth);
@Unique
public String crashpatch$wrapFormattedStringToWidth(String str, int wrapWidth) {
int i = this.crashpatch$sizeStringToWidth(str, wrapWidth);

if (str.length() <= i)
{
if (str.length() <= i) {
return str;
}
else
{
} else {
String s = str.substring(0, i);
char c0 = str.charAt(i);
boolean flag = c0 == 32 || c0 == 10;
String s1 = FontRenderer.getFormatFromString(s) + str.substring(i + (flag ? 1 : 0));
return s + "\n" + this.wrapFormattedStringToWidth(s1, wrapWidth);
return s + "\n" + this.crashpatch$wrapFormattedStringToWidth(s1, wrapWidth);
}
}

private int sizeStringToWidth(String str, int wrapWidth)
{
@Unique
private int crashpatch$sizeStringToWidth(String str, int wrapWidth) {
int i = str.length();
int j = 0;
int k = 0;
int l = -1;

for (boolean flag = false; k < i; ++k)
{
for (boolean flag = false; k < i; ++k) {
char c0 = str.charAt(k);

switch (c0)
{
switch (c0) {
case '\n':
--k;
break;
Expand All @@ -95,51 +93,43 @@ private int sizeStringToWidth(String str, int wrapWidth)
default:
j += fontRendererObj.getCharWidth(c0);

if (flag)
{
if (flag) {
++j;
}

break;
case '\u00a7':

if (k < i - 1)
{
if (k < i - 1) {
++k;
char c1 = str.charAt(k);

if (c1 != 108 && c1 != 76)
{
if (c1 == 114 || c1 == 82 || isFormatColor(c1))
{
if (c1 != 108 && c1 != 76) {
if (c1 == 114 || c1 == 82 || crashpatch$isFormatColor(c1)) {
flag = false;
}
}
else
{
} else {
flag = true;
}
}
}

if (c0 == 10)
{
if (c0 == 10) {
++k;
l = k;
break;
}

if (j > wrapWidth)
{
if (j > wrapWidth) {
break;
}
}

return k != i && l != -1 && l < k ? l : k;
}

private static boolean isFormatColor(char colorChar)
{
@Unique
private static boolean crashpatch$isFormatColor(char colorChar) {
return colorChar >= 48 && colorChar <= 57 || colorChar >= 97 && colorChar <= 102 || colorChar >= 65 && colorChar <= 70;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import net.minecraftforge.fml.common.DuplicateModsFoundException;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.ModContainer;
import org.polyfrost.crashpatch.CrashPatchKt;
import org.polyfrost.crashpatch.CrashPatchOldKt;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand Down Expand Up @@ -40,7 +40,7 @@ private void onInit(CallbackInfo ci) {
protected void actionPerformed(GuiButton button) {
switch (button.id) {
case 0:
UDesktop.open(new File(CrashPatchKt.getMcDir(), "mods"));
UDesktop.open(new File(CrashPatchOldKt.getMcDir(), "mods"));
break;
case 1:
FMLCommonHandler.instance().exitJava(0, false);
Expand All @@ -62,7 +62,7 @@ private void onDrawScreen(int mouseX, int mouseY, float partialTicks, CallbackIn

offset += 10;

drawSplitString(EnumChatFormatting.BOLD + "To fix this, go into your mods folder by clicking the button below or going to " + CrashPatchKt.getMcDir().getAbsolutePath() + " and deleting the duplicate mods.", width / 2, offset, width, Color.BLUE.getRGB());
drawSplitString(EnumChatFormatting.BOLD + "To fix this, go into your mods folder by clicking the button below or going to " + CrashPatchOldKt.getMcDir().getAbsolutePath() + " and deleting the duplicate mods.", width / 2, offset, width, Color.BLUE.getRGB());

for (GuiButton guiButton : this.buttonList) {
guiButton.drawButton(this.mc, mouseX, mouseY);
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/polyfrost/crashpatch/mixin/MixinMinecraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.polyfrost.crashpatch.CrashPatch;
import org.polyfrost.crashpatch.config.CrashPatchConfig;
import org.polyfrost.crashpatch.crashes.StateManager;
import org.polyfrost.crashpatch.gui.CrashGuiRewrite;
import org.polyfrost.crashpatch.gui.CrashUI;
import org.polyfrost.crashpatch.hooks.MinecraftHook;
import org.polyfrost.crashpatch.utils.GuiDisconnectedHook;
import org.spongepowered.asm.mixin.Final;
Expand Down Expand Up @@ -230,7 +230,7 @@ private void onGUIDisplay(GuiScreen i, CallbackInfo ci) {

// Display the crash screen
// crashpatch$runGUILoop(new GuiCrashScreen(report));
displayGuiScreen(new CrashGuiRewrite(report).create());
displayGuiScreen(new CrashUI(report).create());
} catch (Throwable t) {
// The crash screen has crashed. Report it normally instead.
logger.error("An uncaught exception occured while displaying the crash screen, making normal report instead", t);
Expand Down Expand Up @@ -263,7 +263,7 @@ private void onGUIDisplay(GuiScreen i, CallbackInfo ci) {

if (crashpatch$clientCrashCount >= CrashPatchConfig.INSTANCE.getLeaveLimit() || crashpatch$serverCrashCount >= CrashPatchConfig.INSTANCE.getLeaveLimit()) {
logger.error("Crash limit reached, exiting world");
CrashGuiRewrite.Companion.setLeaveWorldCrash(true);
CrashUI.Companion.setLeaveWorldCrash(true);
if (getNetHandler() != null) {
getNetHandler().getNetworkManager().closeChannel(new ChatComponentText("[CrashPatch] Client crashed"));
}
Expand Down Expand Up @@ -333,7 +333,7 @@ private void onGUIDisplay(GuiScreen i, CallbackInfo ci) {
GlStateManager.enableTexture2D();
} catch (Throwable ignored) {
}
crashpatch$runGUILoop(new CrashGuiRewrite(report, CrashGuiRewrite.GuiType.INIT));
crashpatch$runGUILoop(new CrashUI(report, CrashUI.GuiType.INIT));
} catch (Throwable t) {
if (!crashpatch$letDie) {
logger.error("An uncaught exception occured while displaying the init error screen, making normal report instead", t);
Expand All @@ -346,8 +346,8 @@ private void onGUIDisplay(GuiScreen i, CallbackInfo ci) {
/**
* @author Runemoro
*/
private void crashpatch$runGUILoop(CrashGuiRewrite crashGui) throws Throwable {
GuiScreen screen = crashGui.create();
private void crashpatch$runGUILoop(CrashUI crashUI) throws Throwable {
GuiScreen screen = crashUI.create();
displayGuiScreen(screen);
while (running && currentScreen != null) {
if (Display.isCreated() && Display.isCloseRequested()) {
Expand Down Expand Up @@ -381,9 +381,9 @@ private void onGUIDisplay(GuiScreen i, CallbackInfo ci) {
int mouseY = height - Mouse.getY() * height / displayHeight - 1;
Gui.drawRect(0, 0, width, height, Color.WHITE.getRGB()); // DO NOT REMOVE THIS! FOR SOME REASON NANOVG DOESN'T RENDER WITHOUT IT
currentScreen.drawScreen(mouseX, mouseY, 0);
if (crashGui.getShouldCrash()) {
if (crashUI.getShouldCrash()) {
crashpatch$letDie = true;
throw Objects.requireNonNull(crashGui.getThrowable());
throw Objects.requireNonNull(crashUI.getThrowable());
}

framebufferMc.unbindFramebuffer();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.polyfrost.crashpatch.mixin;

//#if FORGE
import org.polyfrost.crashpatch.crashes.StateManager;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.tileentity.TileEntity;
Expand Down Expand Up @@ -50,3 +51,4 @@ private void setDrawingBatchFalse(int pass, CallbackInfo ci) {
drawingBatch = false;
}
}
//#endif
Loading

0 comments on commit 1f53734

Please sign in to comment.