From 0b2f13ec32cd14ff07e7d029989d410fe0842e02 Mon Sep 17 00:00:00 2001 From: ev chang Date: Sat, 27 Jul 2024 04:07:02 +0900 Subject: [PATCH] update to twoconfig, crash gui slightly ported --- build.gradle.kts | 12 +- gradle/wrapper/gradle-wrapper.properties | 2 +- main.py | 93 ++ settings.gradle.kts | 2 +- .../crashpatch/hooks/ModsCheckerPlugin.java | 106 ++- .../crashpatch/mixin/MixinGuiConnecting.java | 4 +- .../crashpatch/mixin/MixinGuiDupesFound.java | 2 +- .../crashpatch/mixin/MixinMinecraft.java | 52 +- .../org/polyfrost/crashpatch/CrashPatch.kt | 46 +- .../crashpatch/config/CrashPatchConfig.kt | 54 +- .../crashpatch/crashes/CrashHelper.kt | 6 +- .../org/polyfrost/crashpatch/gui/CrashGui.kt | 870 +++++++++--------- .../crashpatch/gui/CrashGuiRewrite.kt | 100 ++ .../org/polyfrost/crashpatch/gui/constants.kt | 25 +- .../crashpatch/utils/GuiDisconnectedHook.kt | 6 +- .../crashpatch/utils/InternetUtils.kt | 2 +- 16 files changed, 771 insertions(+), 611 deletions(-) create mode 100644 main.py create mode 100644 src/main/kotlin/org/polyfrost/crashpatch/gui/CrashGuiRewrite.kt diff --git a/build.gradle.kts b/build.gradle.kts index a3b3415..f88d63b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -53,6 +53,8 @@ loom { runConfigs { "client" { programArgs("--tweakClass", "org.polyfrost.crashpatch.hooks.ModsCheckerPlugin") + programArgs("--tweakClass", "org.polyfrost.oneconfig.internal.legacy.OneConfigTweaker") + programArgs("--tweakClass", "org.spongepowered.asm.launch.MixinTweaker") //property("fml.coreMods.load", "") property("mixin.debug.export", "true") } @@ -83,19 +85,25 @@ sourceSets { // Adds the Polyfrost maven repository so that we can get the libraries necessary to develop the mod. repositories { maven("https://repo.polyfrost.org/releases") + maven("https://repo.polyfrost.org/snapshots") } // Configures the libraries/dependencies for your mod. dependencies { // Adds the OneConfig library, so we can develop with it. - modCompileOnly("cc.polyfrost:oneconfig-$platform:0.2.2-alpha+") + val oneconfig = "1.0.0-alpha.19" + implementation("org.polyfrost.oneconfig:config-impl:$oneconfig") + implementation("org.polyfrost.oneconfig:commands:$oneconfig") + implementation("org.polyfrost.oneconfig:events:$oneconfig") + implementation("org.polyfrost.oneconfig:ui:$oneconfig") + implementation("org.polyfrost.oneconfig:internal:$oneconfig") + modImplementation("org.polyfrost.oneconfig:$platform:$oneconfig") modRuntimeOnly("me.djtheredstoner:DevAuth-${if (platform.isFabric) "fabric" else if (platform.isLegacyForge) "forge-legacy" else "forge-latest"}:1.2.0") shade("gs.mclo:api:3.0.1") // If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier. if (platform.isLegacyForge) { compileOnly("org.spongepowered:mixin:0.7.11-SNAPSHOT") - shade("cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta17") } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7431fb5..f136d42 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip diff --git a/main.py b/main.py new file mode 100644 index 0000000..b851061 --- /dev/null +++ b/main.py @@ -0,0 +1,93 @@ +import os +import pathlib + +def add_import(imports): + with open(dir, "w") as new_file: + if original_text != content: + package_index = original_text.find('package') + line_end_index = original_text.find('\n', package_index) + + modified_text = content[:line_end_index] + '\nimport ' + imports + + if name.endswith(".java"): + modified_text += ";" + modified_text += "\n" + content[line_end_index:] + new_file.write(modified_text) + else: + new_file.write(content) + + +input("MAKE SURE YOU HAVE MADE A BACKUP OF YOUR PROJECT BEFORE RUNNING THIS SCRIPT (press enter to continue)\n") + +try: + os.chdir('src') +except FileNotFoundError: + input('Please put this script next to the src/ directory! (press enter to exit)') + exit() + +for path, _, files in os.walk("."): + for name in files: + dir = str(pathlib.PurePath(path, name)) + if not (name.endswith(".java") or name.endswith(".kt")): + continue + + with open(dir,"r+") as f: + new_f = f.readlines() + f.seek(0) + for line in new_f: + if "import cc.polyfrost.oneconfig.config.core.OneColor" in line: + f.write(line.replace("cc.polyfrost.oneconfig.config.core.OneColor", "org.polyfrost.polyui.color.PolyColor")) + elif "import cc.polyfrost.oneconfig.config.core.OneKeyBind" in line: + f.write(line.replace("cc.polyfrost.oneconfig.config.core.OneKeyBind", "org.polyfrost.polyui.input.Keybinder.Bind")) + if "import cc.polyfrost.oneconfig.config" in line: + f.write(line.replace("cc.polyfrost.oneconfig.config", "org.polyfrost.oneconfig.api.config.v1")) + elif "import cc.polyfrost.oneconfig.utils.commands.annotations" in line: + f.write(line.replace("cc.polyfrost.oneconfig.utils.commands.annotations", "org.polyfrost.oneconfig.api.commands.v1.factories.annotated")) + elif "import cc.polyfrost.oneconfig.utils.commands" in line: + f.write(line.replace("cc.polyfrost.oneconfig.utils.commands", "org.polyfrost.oneconfig.api.commands.v1")) + elif "import cc.polyfrost.oneconfig.utils.hypixel" in line: + f.write(line.replace("cc.polyfrost.oneconfig.utils.hypixel", "org.polyfrost.oneconfig.api.hypixel.v1")) + elif "import cc.polyfrost.oneconfig.utils.Notifications" in line: + f.write(line.replace("cc.polyfrost.oneconfig.utils.Notifications", "org.polyfrost.oneconfig.api.ui.v1.notifications.Notifications")) + elif "import cc.polyfrost.oneconfig.utils" in line: + f.write(line.replace("cc.polyfrost.oneconfig.utils", "org.polyfrost.oneconfig.utils.v1")) + elif "import cc.polyfrost.oneconfig.platform" in line: + f.write(line.replace("cc.polyfrost.oneconfig.platform", "org.polyfrost.oneconfig.api.platform.v1")) + elif "import cc.polyfrost.oneconfig.events.event" in line: + f.write(line.replace("cc.polyfrost.oneconfig.events", "org.polyfrost.oneconfig.api.event.v1.events")) + elif "import cc.polyfrost.oneconfig.events" in line: + f.write(line.replace("cc.polyfrost.oneconfig.events", "org.polyfrost.oneconfig.api.event.v1")) + elif "import cc.polyfrost.oneconfig.libs.universal" in line: + f.write(line.replace("cc.polyfrost.oneconfig.libs.universal", "org.polyfrost.universal")) + elif "import cc.polyfrost" in line: + f.write(line.replace("cc.polyfrost", "org.polyfrost")) + else: + f.write(line) + + f.truncate() + +input("Finished removing OneConfig V0 imports.\n\nPress enter to start replacing V0 methods.\n") + +for path, _, files in os.walk("."): + for name in files: + dir = str(pathlib.PurePath(path, name)) + if not (name.endswith(".java") or name.endswith(".kt")): + continue + + with open(dir, "r") as file: + original_text = file.read() + with open(dir, "r+") as file: + content = file.read().replace("TickDelay", "EventDelay.ticks").replace("tick(", "EventDelay.ticks(").replace("RenderTickDelay", "EventDelay.render").replace("renderTick(", "EventDelay.render(") + add_import("org.polyfrost.oneconfig.api.event.v1.EventDelay") + + with open(dir, "r") as file: + original_text = file.read() + with open(dir, "r+") as file: + content = file.read().replace("OneColor", "PolyColor") + + with open(dir, "r") as file: + original_text = file.read() + with open(dir, "r+") as file: + content = file.read().replace("OneKeyBind", "Keybinder.Bind") + +input("Done! (press enter to exit)") \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 6973a98..401cef3 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -7,7 +7,7 @@ pluginManagement { maven("https://repo.polyfrost.org/releases") // Adds the Polyfrost maven repository to get Polyfrost Gradle Toolkit } plugins { - val pgtVersion = "0.6.2" // Sets the default versions for Polyfrost Gradle Toolkit + val pgtVersion = "0.6.5" // Sets the default versions for Polyfrost Gradle Toolkit id("org.polyfrost.multi-version.root") version pgtVersion } } diff --git a/src/main/java/org/polyfrost/crashpatch/hooks/ModsCheckerPlugin.java b/src/main/java/org/polyfrost/crashpatch/hooks/ModsCheckerPlugin.java index bb00501..0e6d6f5 100644 --- a/src/main/java/org/polyfrost/crashpatch/hooks/ModsCheckerPlugin.java +++ b/src/main/java/org/polyfrost/crashpatch/hooks/ModsCheckerPlugin.java @@ -1,6 +1,5 @@ package org.polyfrost.crashpatch.hooks; -import cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker; import com.google.common.collect.Lists; import com.google.gson.JsonObject; import com.google.gson.JsonParser; @@ -32,10 +31,15 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; -public class ModsCheckerPlugin extends LaunchWrapperTweaker { +public class ModsCheckerPlugin implements ITweaker { //todo private static final JsonParser PARSER = new JsonParser(); public static final HashMap> modsMap = new HashMap<>(); //modid : file, version, name + @Override + public void acceptOptions(List args, File gameDir, File assetsDir, String profile) { + + } + @Override public void injectIntoClassLoader(LaunchClassLoader classLoader) { try { @@ -127,51 +131,63 @@ public void injectIntoClassLoader(LaunchClassLoader classLoader) { e.printStackTrace(); } - CodeSource codeSource = this.getClass().getProtectionDomain().getCodeSource(); - if (codeSource != null) { - URL location = codeSource.getLocation(); - try { - File file = new File(location.toURI()); - if (file.isFile()) { - CoreModManager.getIgnoredMods().remove(file.getName()); - CoreModManager.getReparseableCoremods().add(file.getName()); - try { - try { - List tweakClasses = (List) Launch.blackboard.get("TweakClasses"); // tweak classes before other mod trolling - if (tweakClasses.contains("org.spongepowered.asm.launch.MixinTweaker")) { // if there's already a mixin tweaker, we'll just load it like "usual" - new MixinTweaker(); // also we might not need to make a new mixin tweawker all the time but im just making sure - } else if (!Launch.blackboard.containsKey("mixin.initialised")) { // if there isnt, we do our own trolling - List tweaks = (List) Launch.blackboard.get("Tweaks"); - tweaks.add(new MixinTweaker()); - } - } catch (Exception ignored) { - // if it fails i *think* we can just ignore it - } - try { - MixinBootstrap.getPlatform().addContainer(location.toURI()); - } catch (Exception ignore) { - // fuck you essential - try { - Class containerClass = Class.forName("org.spongepowered.asm.launch.platform.container.IContainerHandle"); - Class urlContainerClass = Class.forName("org.spongepowered.asm.launch.platform.container.ContainerHandleURI"); - Object container = urlContainerClass.getConstructor(URI.class).newInstance(location.toURI()); - MixinBootstrap.getPlatform().getClass().getDeclaredMethod("addContainer", containerClass).invoke(MixinBootstrap.getPlatform(), container); - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException("OneConfig's Mixin loading failed. Please contact https://polyfrost.cc/discord to resolve this issue!"); - } - } - } catch (Exception ignored) { + //todo terrible + + //CodeSource codeSource = this.getClass().getProtectionDomain().getCodeSource(); + //if (codeSource != null) { + // URL location = codeSource.getLocation(); + // try { + // File file = new File(location.toURI()); + // if (file.isFile()) { + // CoreModManager.getIgnoredMods().remove(file.getName()); + // CoreModManager.getReparseableCoremods().add(file.getName()); + // try { + // try { + // List tweakClasses = (List) Launch.blackboard.get("TweakClasses"); // tweak classes before other mod trolling + // if (tweakClasses.contains("org.spongepowered.asm.launch.MixinTweaker")) { // if there's already a mixin tweaker, we'll just load it like "usual" + // new MixinTweaker(); // also we might not need to make a new mixin tweawker all the time but im just making sure + // } else if (!Launch.blackboard.containsKey("mixin.initialised")) { // if there isnt, we do our own trolling + // List tweaks = (List) Launch.blackboard.get("Tweaks"); + // tweaks.add(new MixinTweaker()); + // } + // } catch (Exception ignored) { + // // if it fails i *think* we can just ignore it + // } + // try { + // MixinBootstrap.getPlatform().addContainer(location.toURI()); + // } catch (Exception ignore) { + // // fuck you essential + // try { + // Class containerClass = Class.forName("org.spongepowered.asm.launch.platform.container.IContainerHandle"); + // Class urlContainerClass = Class.forName("org.spongepowered.asm.launch.platform.container.ContainerHandleURI"); + // Object container = urlContainerClass.getConstructor(URI.class).newInstance(location.toURI()); + // MixinBootstrap.getPlatform().getClass().getDeclaredMethod("addContainer", containerClass).invoke(MixinBootstrap.getPlatform(), container); + // } catch (Exception e) { + // e.printStackTrace(); + // throw new RuntimeException("OneConfig's Mixin loading failed. Please contact https://polyfrost.cc/discord to resolve this issue!"); + // } + // } + // } catch (Exception ignored) { +// + // } + // } + // } catch (URISyntaxException ignored) {} + //} else { + // LogManager.getLogger().warn("No CodeSource, if this is not a development environment we might run into problems!"); + // LogManager.getLogger().warn(this.getClass().getProtectionDomain()); + //} +// + //super.injectIntoClassLoader(classLoader); + } - } - } - } catch (URISyntaxException ignored) {} - } else { - LogManager.getLogger().warn("No CodeSource, if this is not a development environment we might run into problems!"); - LogManager.getLogger().warn(this.getClass().getProtectionDomain()); - } + @Override + public String getLaunchTarget() { + return null; + } - super.injectIntoClassLoader(classLoader); + @Override + public String[] getLaunchArguments() { + return new String[0]; } private static void doThatPopupThing(File modsFolder, String message) { diff --git a/src/main/java/org/polyfrost/crashpatch/mixin/MixinGuiConnecting.java b/src/main/java/org/polyfrost/crashpatch/mixin/MixinGuiConnecting.java index 86acce2..420c592 100644 --- a/src/main/java/org/polyfrost/crashpatch/mixin/MixinGuiConnecting.java +++ b/src/main/java/org/polyfrost/crashpatch/mixin/MixinGuiConnecting.java @@ -1,7 +1,7 @@ package org.polyfrost.crashpatch.mixin; -import cc.polyfrost.oneconfig.libs.universal.ChatColor; -import cc.polyfrost.oneconfig.libs.universal.UDesktop; +import org.polyfrost.universal.ChatColor; +import org.polyfrost.universal.UDesktop; import org.polyfrost.crashpatch.CrashPatch; import org.polyfrost.crashpatch.hooks.MinecraftHook; import net.minecraft.client.Minecraft; diff --git a/src/main/java/org/polyfrost/crashpatch/mixin/MixinGuiDupesFound.java b/src/main/java/org/polyfrost/crashpatch/mixin/MixinGuiDupesFound.java index 0227110..9241d96 100644 --- a/src/main/java/org/polyfrost/crashpatch/mixin/MixinGuiDupesFound.java +++ b/src/main/java/org/polyfrost/crashpatch/mixin/MixinGuiDupesFound.java @@ -1,6 +1,6 @@ package org.polyfrost.crashpatch.mixin; -import cc.polyfrost.oneconfig.libs.universal.UDesktop; +import org.polyfrost.universal.UDesktop; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiErrorScreen; diff --git a/src/main/java/org/polyfrost/crashpatch/mixin/MixinMinecraft.java b/src/main/java/org/polyfrost/crashpatch/mixin/MixinMinecraft.java index 91b6d7f..7cfd1aa 100644 --- a/src/main/java/org/polyfrost/crashpatch/mixin/MixinMinecraft.java +++ b/src/main/java/org/polyfrost/crashpatch/mixin/MixinMinecraft.java @@ -1,24 +1,14 @@ package org.polyfrost.crashpatch.mixin; -import cc.polyfrost.oneconfig.events.EventManager; -import cc.polyfrost.oneconfig.events.event.RenderEvent; -import cc.polyfrost.oneconfig.events.event.Stage; -import cc.polyfrost.oneconfig.utils.gui.GuiUtils; -import net.minecraft.client.multiplayer.WorldClient; -import net.minecraft.client.network.NetHandlerPlayClient; -import net.minecraft.client.renderer.EntityRenderer; -import net.minecraft.util.ChatComponentText; -import org.polyfrost.crashpatch.config.CrashPatchConfig; -import org.polyfrost.crashpatch.crashes.StateManager; -import org.polyfrost.crashpatch.gui.CrashGui; -import org.polyfrost.crashpatch.hooks.MinecraftHook; -import org.polyfrost.crashpatch.utils.GuiDisconnectedHook; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.SoundHandler; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.client.network.NetHandlerPlayClient; +import net.minecraft.client.renderer.EntityRenderer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.texture.TextureManager; @@ -29,6 +19,7 @@ import net.minecraft.client.settings.GameSettings; import net.minecraft.client.shader.Framebuffer; import net.minecraft.crash.CrashReport; +import net.minecraft.util.ChatComponentText; import net.minecraft.util.MinecraftError; import net.minecraft.util.ReportedException; import net.minecraft.util.ResourceLocation; @@ -41,6 +32,11 @@ import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; import org.lwjgl.opengl.GL14; +import org.polyfrost.crashpatch.config.CrashPatchConfig; +import org.polyfrost.crashpatch.crashes.StateManager; +import org.polyfrost.crashpatch.gui.CrashGuiRewrite; +import org.polyfrost.crashpatch.hooks.MinecraftHook; +import org.polyfrost.crashpatch.utils.GuiDisconnectedHook; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -228,7 +224,7 @@ private void onGUIDisplay(GuiScreen i, CallbackInfo ci) { // Display the crash screen // crashpatch$runGUILoop(new GuiCrashScreen(report)); - displayGuiScreen(new CrashGui(report)); + displayGuiScreen(new CrashGuiRewrite(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); @@ -261,7 +257,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"); - CrashGui.Companion.setLeaveWorldCrash$CrashPatch_1_8_9_forge(true); + CrashGuiRewrite.Companion.setLeaveWorldCrash(true); if (getNetHandler() != null) { getNetHandler().getNetworkManager().closeChannel(new ChatComponentText("[CrashPatch] Client crashed")); } @@ -315,12 +311,13 @@ private void onGUIDisplay(GuiScreen i, CallbackInfo ci) { mcSoundHandler = new SoundHandler(mcResourceManager, gameSettings); mcResourceManager.registerReloadListener(mcSoundHandler); - try { // this is necessary for some GUI stuff. if it works, cool, if not, it's not a big deal - //EventManager.INSTANCE.register(Notifications.INSTANCE); - GuiUtils.getDeltaTime(); // make sure static initialization is called - } catch (Exception e) { - e.printStackTrace(); - } + //try { // this is necessary for some GUI stuff. if it works, cool, if not, it's not a big deal + // //EventManager.INSTANCE.register(Notifications.INSTANCE); + // GuiUtils.getDeltaTime(); // make sure static initialization is called + //} catch (Exception e) { + // e.printStackTrace(); + //} + //todo do we need a polyui equivalent running = true; try { @@ -330,7 +327,7 @@ private void onGUIDisplay(GuiScreen i, CallbackInfo ci) { GlStateManager.enableTexture2D(); } catch (Throwable ignored) { } - crashpatch$runGUILoop(new CrashGui(report, CrashGui.GuiType.INIT)); + crashpatch$runGUILoop(new CrashGuiRewrite(report, CrashGuiRewrite.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); @@ -343,13 +340,14 @@ private void onGUIDisplay(GuiScreen i, CallbackInfo ci) { /** * @author Runemoro */ - private void crashpatch$runGUILoop(CrashGui screen) throws Throwable { + private void crashpatch$runGUILoop(CrashGuiRewrite crashGui) throws Throwable { + GuiScreen screen = crashGui.create(); displayGuiScreen(screen); while (running && currentScreen != null) { if (Display.isCreated() && Display.isCloseRequested()) { System.exit(0); } - EventManager.INSTANCE.post(new RenderEvent(Stage.START, 0)); + //EventManager.INSTANCE.post(new RenderEvent.Start()); todo leftClickCounter = 10000; currentScreen.handleInput(); currentScreen.updateScreen(); @@ -377,9 +375,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 (screen.getShouldCrash()) { + if (crashGui.getShouldCrash()) { crashpatch$letDie = true; - throw Objects.requireNonNull(screen.getThrowable()); + throw Objects.requireNonNull(crashGui.getThrowable()); } framebufferMc.unbindFramebuffer(); @@ -389,7 +387,7 @@ private void onGUIDisplay(GuiScreen i, CallbackInfo ci) { framebufferMc.framebufferRender(displayWidth, displayHeight); GlStateManager.popMatrix(); - EventManager.INSTANCE.post(new RenderEvent(Stage.END, 0)); + //EventManager.INSTANCE.post(new RenderEvent(Stage.END, 0)); todo updateDisplay(); Thread.yield(); diff --git a/src/main/kotlin/org/polyfrost/crashpatch/CrashPatch.kt b/src/main/kotlin/org/polyfrost/crashpatch/CrashPatch.kt index b916902..50ef5b2 100644 --- a/src/main/kotlin/org/polyfrost/crashpatch/CrashPatch.kt +++ b/src/main/kotlin/org/polyfrost/crashpatch/CrashPatch.kt @@ -1,13 +1,10 @@ package org.polyfrost.crashpatch -import cc.polyfrost.oneconfig.libs.universal.ChatColor -import cc.polyfrost.oneconfig.libs.universal.UMinecraft -import cc.polyfrost.oneconfig.utils.Multithreading -import cc.polyfrost.oneconfig.utils.commands.CommandManager -import cc.polyfrost.oneconfig.utils.commands.annotations.Command -import cc.polyfrost.oneconfig.utils.commands.annotations.Main -import cc.polyfrost.oneconfig.utils.commands.annotations.SubCommand -import cc.polyfrost.oneconfig.utils.dsl.tick +import org.polyfrost.universal.ChatColor +import org.polyfrost.universal.UMinecraft +import org.polyfrost.oneconfig.utils.v1.Multithreading +import org.polyfrost.oneconfig.api.commands.v1.CommandManager +import org.polyfrost.oneconfig.api.commands.v1.factories.annotated.Command import org.polyfrost.crashpatch.config.CrashPatchConfig import org.polyfrost.crashpatch.crashes.CrashHelper import org.polyfrost.crashpatch.crashes.DeobfuscatingRewritePolicy @@ -21,7 +18,7 @@ import org.apache.logging.log4j.Logger import java.io.File -@Mod(modid = CrashPatch.MODID, version = CrashPatch.VERSION, name = CrashPatch.NAME, modLanguageAdapter = "cc.polyfrost.oneconfig.utils.KotlinLanguageAdapter") +@Mod(modid = CrashPatch.MODID, version = CrashPatch.VERSION, name = CrashPatch.NAME, modLanguageAdapter = "org.polyfrost.oneconfig.utils.v1.forge.KotlinLanguageAdapter") object CrashPatch { const val MODID = "@ID@" const val NAME = "@NAME@" @@ -32,7 +29,7 @@ object CrashPatch { @Mod.EventHandler fun onPreInit(e: FMLPreInitializationEvent) { DeobfuscatingRewritePolicy.install() - Multithreading.runAsync { + Multithreading.submit { logger.info("Is SkyClient: $isSkyclient") if (!CrashHelper.loadJson()) { logger.error("CrashHelper failed to preload crash data JSON!") @@ -42,20 +39,20 @@ object CrashPatch { @Mod.EventHandler fun onInit(e: FMLInitializationEvent) { - CommandManager.INSTANCE.registerCommand(CrashPatchCommand()) + CommandManager.registerCommand(CrashPatchCommand()) CrashPatchConfig // uncomment to test init screen crashes // throw Throwable("java.lang.NoClassDefFoundError: xyz/matthewtgm/requisite/keybinds/KeyBind at lumien.custommainmenu.configuration.ConfigurationLoader.load(ConfigurationLoader.java:142) club.sk1er.bossbarcustomizer.BossbarMod.loadConfig cc.woverflow.hytils.handlers.chat.modules.modifiers.DefaultChatRestyler Failed to login: null The Hypixel Alpha server is currently closed! net.kdt.pojavlaunch macromodmodules") } - @Command(value = "crashpatch") + @Command("crashpatch") class CrashPatchCommand { - @Main + @Command fun main() { - CrashPatchConfig.openGui() + //CrashPatchConfig.openGui() } - @SubCommand + @Command fun reload() { if (CrashHelper.loadJson()) { CrashHelper.simpleCache.clear() @@ -64,21 +61,6 @@ object CrashPatch { UMinecraft.getMinecraft().thePlayer.addChatMessage(ChatComponentText("${ChatColor.RED}[CrashPatch] Failed to reload the JSON file!")) } } - - var a = false - - @SubCommand - fun crash() { - UMinecraft.getMinecraft().thePlayer.addChatMessage(ChatComponentText("${ChatColor.RED}[CrashPatch] Crashing...")) - tick(1) { - if (!a) { - a = true - throw Throwable("java.lang.NoClassDefFoundError: xyz/matthewtgm/requisite/keybinds/KeyBind at lumien.custommainmenu.configuration.ConfigurationLoader.load(ConfigurationLoader.java:142) club.sk1er.bossbarcustomizer.BossbarMod.loadConfig cc.woverflow.hytils.handlers.chat.modules.modifiers.DefaultChatRestyler Failed to login: null The Hypixel Alpha server is currently closed! net.kdt.pojavlaunch macromodmodules") - } else { - a = false - } - } - } } } val logger: Logger = LogManager.getLogger(CrashPatch) @@ -91,4 +73,6 @@ val gameDir: File by lazy(LazyThreadSafetyMode.PUBLICATION) { file } } -val mcDir = File(System.getProperty("user.dir")) \ No newline at end of file +val mcDir = File(System.getProperty("user.dir")) +val mc + get() = UMinecraft.getMinecraft() // todo replace with oneconfig in alpha20 \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/crashpatch/config/CrashPatchConfig.kt b/src/main/kotlin/org/polyfrost/crashpatch/config/CrashPatchConfig.kt index 93ffad5..13b3428 100644 --- a/src/main/kotlin/org/polyfrost/crashpatch/config/CrashPatchConfig.kt +++ b/src/main/kotlin/org/polyfrost/crashpatch/config/CrashPatchConfig.kt @@ -1,75 +1,71 @@ package org.polyfrost.crashpatch.config -import cc.polyfrost.oneconfig.config.Config -import cc.polyfrost.oneconfig.config.annotations.* -import cc.polyfrost.oneconfig.config.data.InfoType -import cc.polyfrost.oneconfig.config.data.Mod -import cc.polyfrost.oneconfig.config.data.ModType -import cc.polyfrost.oneconfig.libs.universal.UDesktop.browse +import org.polyfrost.oneconfig.api.config.v1.Config +import org.polyfrost.oneconfig.api.config.v1.annotations.* +import org.polyfrost.universal.UDesktop.browse import java.net.URI -object CrashPatchConfig : Config(Mod("CrashPatch", ModType.UTIL_QOL, "/assets/crashpatch/crashpatch_dark.svg"), "crashpatch.json") { +object CrashPatchConfig : Config("crashpatch.json", "/assets/crashpatch/crashpatch_dark.svg", "CrashPatch", Category.QOL) { // Toggles @Switch( - name = "Catch crashes during gameplay", + title = "Catch crashes during gameplay", description = "Catch crashes whilst in-game, and prevent the game from closing", subcategory = "Patches" ) var inGameCrashPatch = true @Switch( - name = "Patch crashes during launch", + title = "Patch crashes during launch", description = "Catch crashes during initialization, & display a message.", subcategory = "Patches" ) var initCrashPatch = true @Switch( - name = "Display disconnection causes", + title = "Display disconnection causes", description = "Display a message when a reason is found for a disconnect.", subcategory = "Patches" ) var disconnectCrashPatch = true // Limits - @Info( - text = "It's recommended to leave the world after a few crashes, and outright quit the game if there are more; this is to avoid severe instability", - type = InfoType.WARNING, - size = 2, - subcategory = "Limits" - ) - var ignored: Boolean = false + //@Info( // todo + // text = "It's recommended to leave the world after a few crashes, and outright quit the game if there are more; this is to avoid severe instability", + // type = InfoType.WARNING, + // size = 2, + // subcategory = "Limits" + //) + //var ignored: Boolean = false @Slider( - name = "World Leave Limit", + title = "World Leave Limit", min = 1f, max = 20f, - step = 1, + step = 1F, subcategory = "Limits" ) var leaveLimit = 3 @Slider( - name = "Crash Limit", + title = "Crash Limit", min = 1f, max = 20f, - step = 1, + step = 1F, subcategory = "Limits" ) var crashLimit = 5 @Switch( - name = "Deobfuscate Crash Log", + title = "Deobfuscate Crash Log", description = "Makes certain class names more readable through deobfuscation", - size = 2, subcategory = "Logs" ) var deobfuscateCrashLog = true @Dropdown( - name = "Log uploader", + title = "Log uploader", description = "The method used to upload the crash log.", options = ["hst.sh", "mclo.gs (Aternos)"], subcategory = "Logs" @@ -77,12 +73,14 @@ object CrashPatchConfig : Config(Mod("CrashPatch", ModType.UTIL_QOL, "/assets/cr var crashLogUploadMethod = 0 @Button( - name = "Polyfrost support", + title = "Polyfrost support", text = "Discord" ) var supportDiscord = Runnable { browse(URI.create("https://polyfrost.cc/discord/")) } - init { - initialize() - } + @Button( + title = "Crash game", + text = "Crash" + ) + var crashGame = Runnable { throw Throwable("java.lang.NoClassDefFoundError: xyz/matthewtgm/requisite/keybinds/KeyBind at lumien.custommainmenu.configuration.ConfigurationLoader.load(ConfigurationLoader.java:142) club.sk1er.bossbarcustomizer.BossbarMod.loadConfig cc.woverflow.hytils.handlers.chat.modules.modifiers.DefaultChatRestyler Failed to login: null The Hypixel Alpha server is currently closed! net.kdt.pojavlaunch macromodmodules") } } \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/crashpatch/crashes/CrashHelper.kt b/src/main/kotlin/org/polyfrost/crashpatch/crashes/CrashHelper.kt index fef026c..b5924aa 100644 --- a/src/main/kotlin/org/polyfrost/crashpatch/crashes/CrashHelper.kt +++ b/src/main/kotlin/org/polyfrost/crashpatch/crashes/CrashHelper.kt @@ -1,10 +1,10 @@ package org.polyfrost.crashpatch.crashes -import cc.polyfrost.oneconfig.libs.universal.wrappers.message.UTextComponent -import cc.polyfrost.oneconfig.utils.NetworkUtils +import org.polyfrost.universal.wrappers.message.UTextComponent import org.polyfrost.crashpatch.gameDir import org.polyfrost.crashpatch.mcDir import com.google.gson.JsonObject +import org.polyfrost.oneconfig.utils.v1.JsonUtils import java.io.File import kotlin.collections.set @@ -17,7 +17,7 @@ object CrashHelper { fun loadJson(): Boolean { return try { skyclientJson = - NetworkUtils.getJsonElement("https://raw.githubusercontent.com/SkyblockClient/CrashData/main/crashes.json").asJsonObject + JsonUtils.parseFromUrl("https://raw.githubusercontent.com/SkyblockClient/CrashData/main/crashes.json")?.asJsonObject ?: return false true } catch (e: Exception) { e.printStackTrace() diff --git a/src/main/kotlin/org/polyfrost/crashpatch/gui/CrashGui.kt b/src/main/kotlin/org/polyfrost/crashpatch/gui/CrashGui.kt index 53708e9..5894de7 100644 --- a/src/main/kotlin/org/polyfrost/crashpatch/gui/CrashGui.kt +++ b/src/main/kotlin/org/polyfrost/crashpatch/gui/CrashGui.kt @@ -1,454 +1,420 @@ package org.polyfrost.crashpatch.gui -import cc.polyfrost.oneconfig.gui.OneConfigGui -import cc.polyfrost.oneconfig.gui.animations.Animation -import cc.polyfrost.oneconfig.gui.animations.ColorAnimation -import cc.polyfrost.oneconfig.gui.animations.EaseInOutQuad -import cc.polyfrost.oneconfig.gui.animations.EaseOutQuad -import cc.polyfrost.oneconfig.gui.elements.BasicButton -import cc.polyfrost.oneconfig.libs.universal.UDesktop -import cc.polyfrost.oneconfig.libs.universal.UMatrixStack -import cc.polyfrost.oneconfig.libs.universal.UResolution.windowHeight -import cc.polyfrost.oneconfig.libs.universal.UResolution.windowWidth -import cc.polyfrost.oneconfig.libs.universal.UScreen -import cc.polyfrost.oneconfig.platform.Platform -import cc.polyfrost.oneconfig.renderer.NanoVGHelper -import cc.polyfrost.oneconfig.renderer.asset.Icon -import cc.polyfrost.oneconfig.renderer.asset.SVG -import cc.polyfrost.oneconfig.renderer.font.Font -import cc.polyfrost.oneconfig.renderer.font.FontHelper -import cc.polyfrost.oneconfig.renderer.font.Fonts -import cc.polyfrost.oneconfig.renderer.scissor.ScissorHelper -import cc.polyfrost.oneconfig.utils.InputHandler -import cc.polyfrost.oneconfig.utils.NetworkUtils -import cc.polyfrost.oneconfig.utils.Notifications -import cc.polyfrost.oneconfig.utils.color.ColorPalette -import cc.polyfrost.oneconfig.utils.color.ColorUtils -import cc.polyfrost.oneconfig.utils.dsl.* -import net.minecraft.crash.CrashReport -import org.polyfrost.crashpatch.CrashPatch -import org.polyfrost.crashpatch.crashes.CrashHelper -import org.polyfrost.crashpatch.crashes.CrashScan -import org.polyfrost.crashpatch.hooks.CrashReportHook -import org.polyfrost.crashpatch.utils.InternetUtils -import java.io.File -import java.net.URI - -class CrashGui @JvmOverloads constructor( - private val scanText: String, - private val file: File?, - private val susThing: String, - private val type: GuiType = GuiType.NORMAL, - val throwable: Throwable? = null -) : UScreen(false) { - @JvmOverloads - constructor(report: CrashReport, type: GuiType = GuiType.NORMAL) : this( - report.completeReport, - report.file, - (report as CrashReportHook).suspectedCrashPatchMods, - type, - report.crashCause - ) - - private val crashPatchLogo = Icon("/assets/crashpatch/crashpatch_dark.svg") - - private val crashScan: CrashScan? by lazy { - return@lazy CrashHelper.scanReport(scanText, type == GuiType.DISCONNECT) - .let { return@let if (it != null && it.solutions.isNotEmpty()) it else null } - } - var shouldCrash = false - - private val subtitle by lazy { - when (type) { - GuiType.INIT -> listOf(SUBTITLE_INIT_1 + (if (crashScan != null) SUBTITLE_INIT_2 else "") + SUBTITLE_INIT_3) - GuiType.NORMAL -> listOf(SUBTITLE_1, SUBTITLE_2) - GuiType.DISCONNECT -> listOf(SUBTITLE_DISCONNECTED, SUBTITLE_DISCONNECTED_2) - } - } - - private val buttonFontSizeField = BasicButton::class.java.getDeclaredField("fontSize").apply { isAccessible = true } - - private val returnToGameButton by lazy { - val button = BasicButton( - NanoVGHelper.INSTANCE.getTextWidth(vg, RETURN_TO_GAME, 14f, Fonts.MEDIUM).toInt() + 40, - 40, - RETURN_TO_GAME, - 2, - ColorPalette.PRIMARY - ) - button.setClickAction { - if (type == GuiType.INIT) { - shouldCrash = true - } else { - restorePreviousScreen() - } - } - buttonFontSizeField.setFloat(button, 14f) - button - } - - private val openCrashLogButton by lazy { - val button = BasicButton( - NanoVGHelper.INSTANCE.getTextWidth(vg, OPEN_CRASH_LOG, 14f, Fonts.MEDIUM).toInt() + 40 + 5 + 35, - 40, - OPEN_CRASH_LOG, - null, - SVG("/assets/crashpatch/open-external.svg"), - 2, - ColorPalette.TERTIARY - ) - button.setClickAction { - file?.let { - UDesktop.open(it) - } - } - buttonFontSizeField.setFloat(button, 14f) - button - } - - private val uploadLogButton by lazy { - val button = BasicButton( - 30, - 30, - SVG("/assets/crashpatch/upload.svg"), - 2, - ColorPalette(GRAY_600, GRAY_700, GRAY_800) - ) - button.setClickAction { - selectedSolution?.let { solution -> - val link = - InternetUtils.upload(solution.solutions.joinToString(separator = "") { it + "\n" } + "\n\n" + (if (!solution.crashReport) scanText else "")) - setClipboardString(link) - if (UDesktop.browse(URI.create(link))) { - Notifications.INSTANCE.send( - "CrashPatch", "Link copied to clipboard and opened in browser", crashPatchLogo - ) - } else { - Notifications.INSTANCE.send( - "CrashPatch", "Couldn't open link in browser, copied to clipboard instead.", crashPatchLogo - ) - } - } - } - button - } - - private val copyLogButton by lazy { - val button = BasicButton( - 30, - 30, - SVG("/assets/crashpatch/copy.svg"), - 2, - ColorPalette(GRAY_600, GRAY_700, GRAY_800) - ) - button.setClickAction { - selectedSolution?.let { solution -> - setClipboardString(solution.solutions.joinToString(separator = "") { it + "\n" } + "\n\n" + (if (!solution.crashReport) scanText else "")) - Notifications.INSTANCE.send("CrashPatch", "Copied to clipboard", crashPatchLogo) - } - } - button - } - - private var scrollAnimation: Animation? = null - private val colorAnimation = ColorAnimation( - ColorPalette( - ColorUtils.getColor(55, 59, 69, 76), - ColorUtils.getColor(55, 59, 69, 153), - ColorUtils.getColor(55, 59, 69, 255) - ), 200 - ) - private var hyperlinkAnimation: EaseInOutQuad? = EaseInOutQuad(200, 0f, 1f, false) - private var scrollTarget = 0f - private var scrollTime = 0L - private var mouseWasDown = false - private var dragging = false - private var yStart = 0f - private var scroll = 0f - - private var lastHeight = 0f - - private var selectedSolution: CrashScan.Solution? = null - - private var vg = -1L - - private val inputHandler = InputHandler() - - override fun onDrawScreen(matrixStack: UMatrixStack, mouseX: Int, mouseY: Int, partialTicks: Float) { - super.onDrawScreen(matrixStack, mouseX, mouseY, partialTicks) - if (mc.theWorld == null && leaveWorldCrash) { - drawDefaultBackground() - } - NanoVGHelper.INSTANCE.setupAndDraw { draw(it, inputHandler) } - } - - override fun onScreenClose() { - super.onScreenClose() - leaveWorldCrash = false - } - - fun draw(vg: Long, inputHandler: InputHandler) { - this.vg = vg - nanoVG(vg) { - FontHelper.INSTANCE.loadFont(vg, JETBRAINS_MONO) - val scale = OneConfigGui.getScaleFactor() - val x = ((windowWidth - 650 * scale) / 2f / scale).toInt() - val y = ((windowHeight - 600 * scale) / 2f / scale).toInt() - scale(scale, scale) - inputHandler.scale(scale.toDouble(), scale.toDouble()) - drawRoundedRect(x, y, 650, 600, 20, GRAY_800) - drawSVG("/assets/crashpatch/WarningTriangle.svg", x + 305 + 10, y + 24 + 10, 20, 20, javaClass) - drawText( - if (type == GuiType.DISCONNECT) DISCONNECTED_TITLE else TITLE, - (windowWidth / 2f / scale) - (getTextWidth( - if (type == GuiType.DISCONNECT) DISCONNECTED_TITLE else TITLE, - 24, - Fonts.MEDIUM - ) / 2f), - y + 56 + 22, - WHITE_90, - 24, - Fonts.MEDIUM - ) - subtitle.forEachIndexed { index, s -> - drawText( - s, - (windowWidth / 2f / scale) - (getTextWidth(s, 14, Fonts.REGULAR) / 2f), - y + 56 + 87 + ((index - 1) * (14 * 1.75)), - WHITE_80, - 14, - Fonts.REGULAR - ) - } - - drawText( - if (type == GuiType.DISCONNECT) CAUSE_TEXT_DISCONNECTED else CAUSE_TEXT, - (windowWidth / 2f / scale) - (getTextWidth( - if (type == GuiType.DISCONNECT) CAUSE_TEXT_DISCONNECTED else CAUSE_TEXT, - 16, - Fonts.REGULAR - ) / 2f), - y + 56 + 87 + 10 + (subtitle.size * (14 * 1.75)), - WHITE_80, - 16, - Fonts.REGULAR - ) - drawText( - susThing, (windowWidth / 2f / scale) - (getTextWidth( - susThing, 18, Fonts.SEMIBOLD - ) / 2f), y + 56 + 87 + 10 + (subtitle.size * (14 * 1.75)) + 30, BLUE_400, 18, Fonts.SEMIBOLD - ) - - drawRoundedRect(x + 50, y + 273, 550, 158, 12, GRAY_700) - ScissorHelper.INSTANCE.scissor(vg, x + 50f, y + 273f, 550f, 37f).let { - drawRoundedRect(x + 50, y + 273, 550, 158, 12, GRAY_600) - ScissorHelper.INSTANCE.resetScissor(vg, it) - } - - crashScan?.solutions?.let { solutions -> - var i = 0 - var lastTextWidth = 0f - solutions.forEach { solution -> - i++ - if (i == 1 && selectedSolution == null) { - selectedSolution = solution - } - drawText( - solution.name, - x + 50 + 24 + (32 * (i - 1)) + (if (i > 1) lastTextWidth else 0f), - y + 273 + 18.5, - WHITE_90, - 12, - Fonts.MEDIUM - ) - val textWidth = getTextWidth(solution.name, 12, Fonts.MEDIUM) - if (selectedSolution != solution) { - if (inputHandler.isAreaClicked( - x + 50 + 24 + (32 * (i - 1)) + (if (i > 1) lastTextWidth else 0f), - y + 273f, - textWidth, - 37f, - ) - ) { - selectedSolution = solution - scroll = 0f - scrollTarget = 0f - scrollTime = 0 - scrollAnimation = null - } - } - val hovered = inputHandler.isAreaHovered( - x + 50 + 24 + (32 * (i - 1)) + (if (i > 1) lastTextWidth else 0f), - y + 273f, - textWidth, - 37f, - ) - lastTextWidth += textWidth - if (selectedSolution == solution || hovered) { - drawRoundedRect( - x + 50 + 24 + (32 * (i - 1)) + (if (i > 1) lastTextWidth - textWidth else 0f), - y + 273 + 35, - textWidth, - 2, - 1, - if (selectedSolution == solution) BLUE_600 else ColorUtils.setAlpha(BLUE_600, 128) - ) - } - if (selectedSolution == solution) { - ScissorHelper.INSTANCE.scissor(vg, x + 50f + 20f, y + 310f, 550f - 20 - 20, 121f) - .let { scissor -> - val scrollBarLength = 89 / lastHeight * 89 - if (lastHeight > 89) { - scroll = scrollAnimation?.get() ?: scrollTarget - val dWheel = Platform.getMousePlatform().dWheel.toFloat() * 0.3f - if (dWheel != 0f) { - scrollTarget += dWheel - if (scrollTarget > 0f) scrollTarget = - 0f else if (scrollTarget < -lastHeight + 89) scrollTarget = -lastHeight + 89 - scrollAnimation = EaseOutQuad(150, scroll, scrollTarget, false) - scrollTime = System.currentTimeMillis() - } else if (scrollAnimation != null && scrollAnimation!!.isFinished) scrollAnimation = - null - if (dragging && inputHandler.isClicked(true)) { - dragging = false - } - } - var height = 0F - translate(0f, scroll) - solution.solutions.forEach { - height += 12 * 1.25f - drawWrappedString( - it, - x + 50 + 20, - y + 310f + height, - 550 - 20 - 20, - WHITE_60, - 12, - 1.25f, - JETBRAINS_MONO - ) - height += NanoVGHelper.INSTANCE.getWrappedStringHeight( - vg, it, 550F, 12F, 1.25f, JETBRAINS_MONO - ) - } - height += 12 * 1.25f - translate(0f, -scroll) - lastHeight = height - ScissorHelper.INSTANCE.resetScissor(vg, scissor) - if (lastHeight > 89) { - val scrollBarY = scroll / lastHeight * 81 - val isMouseDown = Platform.getMousePlatform().isButtonDown(0) - val scrollHover = inputHandler.isAreaHovered( - (x + 50f + 20f + 530f - 14f), - (y + 310f + 16 - scrollBarY), - 12f, - scrollBarLength.toInt().toFloat() - ) - val scrollTimePeriod = System.currentTimeMillis() - scrollTime < 1000 - if (scrollHover && isMouseDown && !mouseWasDown) { - yStart = inputHandler.mouseY() - dragging = true - } - mouseWasDown = isMouseDown - if (dragging) { - scrollTarget = -(inputHandler.mouseY() - yStart) * lastHeight / 89f - if (scrollTarget > 0f) scrollTarget = - 0f else if (scrollTarget < -lastHeight + 89) scrollTarget = - -lastHeight + 89f - scrollAnimation = EaseOutQuad(150, scroll, scrollTarget, false) - } - NanoVGHelper.INSTANCE.drawRoundedRect( - vg, - (x + 50f + 20f + 530f - 14f), - (y + 310f + 16 - scrollBarY), - 4f, - scrollBarLength, - colorAnimation.getColor(scrollHover || scrollTimePeriod, dragging), - 4f - ) - } - } - } - } - } - uploadLogButton.draw(vg, x + 600 - 8 - 11 - 30f, y + 273f + 3.5f, inputHandler) - copyLogButton.draw(vg, x + 600 - 8 - 11 - 15 - 8 - 11 - 30f, y + 273f + 3.5f, inputHandler) - - drawText( - "If the solution above doesn't help, join", (windowWidth / 2f / scale) - (getTextWidth( - "If the solution above doesn't help, join", 16, Fonts.REGULAR - ) / 2f), y + 273 + 158 + 24 + 20, WHITE_80, 16, Fonts.REGULAR - ) - val discordMessageWidth = 20 + 15 + getTextWidth("https://inv.wtf/skyclient", 16, Fonts.REGULAR) - drawSVG( - "/assets/crashpatch/discord.svg", - (windowWidth / 2f / scale) - (discordMessageWidth / 2), - y + 273 + 158 + 24 + 20 + 15, - 20, - 20 - ) - drawURL( - if (CrashPatch.isSkyclient) SKYCLIENT_DISCORD else POLYFROST_DISCORD, - (windowWidth / 2f / scale) - (discordMessageWidth / 2) + 20 + 15, - y + 273 + 158 + 24 + 20 + 15 + 11, - 16, - Fonts.REGULAR, - inputHandler - ) - - val buttonsWidth = - returnToGameButton.width + if (type != GuiType.DISCONNECT) (getTextWidth( - OPEN_CRASH_LOG, - 14, - Fonts.MEDIUM - ) + 16 + 20) + 10 else 0f - returnToGameButton.update((windowWidth / 2f / scale) - (buttonsWidth / 2), y + 600 - 16 - 36f, inputHandler) - returnToGameButton.draw( - vg, (windowWidth / 2f / scale) - (buttonsWidth / 2), y + 600 - 16 - 36f, inputHandler - ) - if (type != GuiType.DISCONNECT) { - openCrashLogButton.update( - (windowWidth / 2f / scale) - (buttonsWidth / 2) + returnToGameButton.width + 10, - y + 600 - 16 - 36f, - inputHandler - ) - openCrashLogButton.draw( - vg, - (windowWidth / 2f / scale) - (buttonsWidth / 2) + returnToGameButton.width + 10, - y + 600 - 16 - 36f, - inputHandler - ) - } - } - } - - private fun VG.drawURL(url: String, x: Number, y: Number, size: Int, font: Font, inputHandler: InputHandler) { - drawText(url, x, y, HYPERLINK_BLUE, size, font) - val length = getTextWidth(url, size, font) - val hovered = inputHandler.isAreaHovered( - (x.toFloat() - 2), (y.toFloat() - size.toFloat()), (length + 4), (size.toFloat() * 2 + 2) - ) - if (hovered || (hyperlinkAnimation != null && (hyperlinkAnimation?.isReversed == false || !hyperlinkAnimation!!.isFinished))) { - if (!hovered && hyperlinkAnimation?.isReversed == false) { - hyperlinkAnimation = EaseInOutQuad(100, 0f, hyperlinkAnimation!!.get(), true) - } - if (hyperlinkAnimation == null) { - hyperlinkAnimation = EaseInOutQuad(100, 0f, 1f, false) - } - drawRect(x, y.toFloat() + size.toFloat() / 2, length, 2, ColorUtils.setAlpha(BLUE_600, (hyperlinkAnimation!!.get() * 255).toInt())) - if (hovered && inputHandler.isClicked) { - NetworkUtils.browseLink(url) - } - } else { - hyperlinkAnimation = null - } - } - - enum class GuiType { - INIT, NORMAL, DISCONNECT - } - - companion object { - internal var leaveWorldCrash = false - } -} \ No newline at end of file +//class CrashGui @JvmOverloads constructor( +// private val scanText: String, +// private val file: File?, +// private val susThing: String, +// private val type: GuiType = GuiType.NORMAL, +// val throwable: Throwable? = null +//) : UScreen(false) { +// @JvmOverloads +// constructor(report: CrashReport, type: GuiType = GuiType.NORMAL) : this( +// report.completeReport, +// report.file, +// (report as CrashReportHook).suspectedCrashPatchMods, +// type, +// report.crashCause +// ) +// +// private val crashPatchLogo = Icon("/assets/crashpatch/crashpatch_dark.svg") +// +// private val crashScan: CrashScan? by lazy { +// return@lazy CrashHelper.scanReport(scanText, type == GuiType.DISCONNECT) +// .let { return@let if (it != null && it.solutions.isNotEmpty()) it else null } +// } +// var shouldCrash = false +// +// private val subtitle by lazy { +// when (type) { +// GuiType.INIT -> listOf(SUBTITLE_INIT_1 + (if (crashScan != null) SUBTITLE_INIT_2 else "") + SUBTITLE_INIT_3) +// GuiType.NORMAL -> listOf(SUBTITLE_1, SUBTITLE_2) +// GuiType.DISCONNECT -> listOf(SUBTITLE_DISCONNECTED, SUBTITLE_DISCONNECTED_2) +// } +// } +// +// private val buttonFontSizeField = BasicButton::class.java.getDeclaredField("fontSize").apply { isAccessible = true } +// +// private val returnToGameButton by lazy { +// val button = BasicButton( +// NanoVGHelper.INSTANCE.getTextWidth(vg, RETURN_TO_GAME, 14f, Fonts.MEDIUM).toInt() + 40, +// 40, +// RETURN_TO_GAME, +// 2, +// ColorPalette.PRIMARY +// ) +// button.setClickAction { +// if (type == GuiType.INIT) { +// shouldCrash = true +// } else { +// restorePreviousScreen() +// } +// } +// buttonFontSizeField.setFloat(button, 14f) +// button +// } +// +// private val openCrashLogButton by lazy { +// val button = BasicButton( +// NanoVGHelper.INSTANCE.getTextWidth(vg, OPEN_CRASH_LOG, 14f, Fonts.MEDIUM).toInt() + 40 + 5 + 35, +// 40, +// OPEN_CRASH_LOG, +// null, +// SVG("/assets/crashpatch/open-external.svg"), +// 2, +// ColorPalette.TERTIARY +// ) +// button.setClickAction { +// file?.let { +// UDesktop.open(it) +// } +// } +// buttonFontSizeField.setFloat(button, 14f) +// button +// } +// +// private val uploadLogButton by lazy { +// val button = BasicButton( +// 30, +// 30, +// SVG("/assets/crashpatch/upload.svg"), +// 2, +// ColorPalette(GRAY_600, GRAY_700, GRAY_800) +// ) +// button.setClickAction { +// selectedSolution?.let { solution -> +// val link = +// InternetUtils.upload(solution.solutions.joinToString(separator = "") { it + "\n" } + "\n\n" + (if (!solution.crashReport) scanText else "")) +// setClipboardString(link) +// if (UDesktop.browse(URI.create(link))) { +// Notifications.INSTANCE.send( +// "CrashPatch", "Link copied to clipboard and opened in browser", crashPatchLogo +// ) +// } else { +// Notifications.INSTANCE.send( +// "CrashPatch", "Couldn't open link in browser, copied to clipboard instead.", crashPatchLogo +// ) +// } +// } +// } +// button +// } +// +// private val copyLogButton by lazy { +// val button = BasicButton( +// 30, +// 30, +// SVG("/assets/crashpatch/copy.svg"), +// 2, +// ColorPalette(GRAY_600, GRAY_700, GRAY_800) +// ) +// button.setClickAction { +// selectedSolution?.let { solution -> +// setClipboardString(solution.solutions.joinToString(separator = "") { it + "\n" } + "\n\n" + (if (!solution.crashReport) scanText else "")) +// Notifications.INSTANCE.send("CrashPatch", "Copied to clipboard", crashPatchLogo) +// } +// } +// button +// } +// +// private var scrollAnimation: Animation? = null +// private val colorAnimation = ColorAnimation( +// ColorPalette( +// ColorUtils.getColor(55, 59, 69, 76), +// ColorUtils.getColor(55, 59, 69, 153), +// ColorUtils.getColor(55, 59, 69, 255) +// ), 200 +// ) +// private var hyperlinkAnimation: EaseInOutQuad? = EaseInOutQuad(200, 0f, 1f, false) +// private var scrollTarget = 0f +// private var scrollTime = 0L +// private var mouseWasDown = false +// private var dragging = false +// private var yStart = 0f +// private var scroll = 0f +// +// private var lastHeight = 0f +// +// private var selectedSolution: CrashScan.Solution? = null +// +// private var vg = -1L +// +// private val inputHandler = InputHandler() +// +// override fun onDrawScreen(matrixStack: UMatrixStack, mouseX: Int, mouseY: Int, partialTicks: Float) { +// super.onDrawScreen(matrixStack, mouseX, mouseY, partialTicks) +// if (mc.theWorld == null && leaveWorldCrash) { +// drawDefaultBackground() +// } +// NanoVGHelper.INSTANCE.setupAndDraw { draw(it, inputHandler) } +// } +// +// override fun onScreenClose() { +// super.onScreenClose() +// leaveWorldCrash = false +// } +// +// fun draw(vg: Long, inputHandler: InputHandler) { +// this.vg = vg +// nanoVG(vg) { +// FontHelper.INSTANCE.loadFont(vg, JETBRAINS_MONO) +// val scale = OneConfigGui.getScaleFactor() +// val x = ((windowWidth - 650 * scale) / 2f / scale).toInt() +// val y = ((windowHeight - 600 * scale) / 2f / scale).toInt() +// scale(scale, scale) +// inputHandler.scale(scale.toDouble(), scale.toDouble()) +// drawRoundedRect(x, y, 650, 600, 20, GRAY_800) +// drawSVG("/assets/crashpatch/WarningTriangle.svg", x + 305 + 10, y + 24 + 10, 20, 20, javaClass) +// drawText( +// if (type == GuiType.DISCONNECT) DISCONNECTED_TITLE else TITLE, +// (windowWidth / 2f / scale) - (getTextWidth( +// if (type == GuiType.DISCONNECT) DISCONNECTED_TITLE else TITLE, +// 24, +// Fonts.MEDIUM +// ) / 2f), +// y + 56 + 22, +// WHITE_90, +// 24, +// Fonts.MEDIUM +// ) +// subtitle.forEachIndexed { index, s -> +// drawText( +// s, +// (windowWidth / 2f / scale) - (getTextWidth(s, 14, Fonts.REGULAR) / 2f), +// y + 56 + 87 + ((index - 1) * (14 * 1.75)), +// WHITE_80, +// 14, +// Fonts.REGULAR +// ) +// } +// +// drawText( +// if (type == GuiType.DISCONNECT) CAUSE_TEXT_DISCONNECTED else CAUSE_TEXT, +// (windowWidth / 2f / scale) - (getTextWidth( +// if (type == GuiType.DISCONNECT) CAUSE_TEXT_DISCONNECTED else CAUSE_TEXT, +// 16, +// Fonts.REGULAR +// ) / 2f), +// y + 56 + 87 + 10 + (subtitle.size * (14 * 1.75)), +// WHITE_80, +// 16, +// Fonts.REGULAR +// ) +// drawText( +// susThing, (windowWidth / 2f / scale) - (getTextWidth( +// susThing, 18, Fonts.SEMIBOLD +// ) / 2f), y + 56 + 87 + 10 + (subtitle.size * (14 * 1.75)) + 30, BLUE_400, 18, Fonts.SEMIBOLD +// ) +// +// drawRoundedRect(x + 50, y + 273, 550, 158, 12, GRAY_700) +// ScissorHelper.INSTANCE.scissor(vg, x + 50f, y + 273f, 550f, 37f).let { +// drawRoundedRect(x + 50, y + 273, 550, 158, 12, GRAY_600) +// ScissorHelper.INSTANCE.resetScissor(vg, it) +// } +// +// crashScan?.solutions?.let { solutions -> +// var i = 0 +// var lastTextWidth = 0f +// solutions.forEach { solution -> +// i++ +// if (i == 1 && selectedSolution == null) { +// selectedSolution = solution +// } +// drawText( +// solution.name, +// x + 50 + 24 + (32 * (i - 1)) + (if (i > 1) lastTextWidth else 0f), +// y + 273 + 18.5, +// WHITE_90, +// 12, +// Fonts.MEDIUM +// ) +// val textWidth = getTextWidth(solution.name, 12, Fonts.MEDIUM) +// if (selectedSolution != solution) { +// if (inputHandler.isAreaClicked( +// x + 50 + 24 + (32 * (i - 1)) + (if (i > 1) lastTextWidth else 0f), +// y + 273f, +// textWidth, +// 37f, +// ) +// ) { +// selectedSolution = solution +// scroll = 0f +// scrollTarget = 0f +// scrollTime = 0 +// scrollAnimation = null +// } +// } +// val hovered = inputHandler.isAreaHovered( +// x + 50 + 24 + (32 * (i - 1)) + (if (i > 1) lastTextWidth else 0f), +// y + 273f, +// textWidth, +// 37f, +// ) +// lastTextWidth += textWidth +// if (selectedSolution == solution || hovered) { +// drawRoundedRect( +// x + 50 + 24 + (32 * (i - 1)) + (if (i > 1) lastTextWidth - textWidth else 0f), +// y + 273 + 35, +// textWidth, +// 2, +// 1, +// if (selectedSolution == solution) BLUE_600 else ColorUtils.setAlpha(BLUE_600, 128) +// ) +// } +// if (selectedSolution == solution) { +// ScissorHelper.INSTANCE.scissor(vg, x + 50f + 20f, y + 310f, 550f - 20 - 20, 121f) +// .let { scissor -> +// val scrollBarLength = 89 / lastHeight * 89 +// if (lastHeight > 89) { +// scroll = scrollAnimation?.get() ?: scrollTarget +// val dWheel = Platform.getMousePlatform().dWheel.toFloat() * 0.3f +// if (dWheel != 0f) { +// scrollTarget += dWheel +// if (scrollTarget > 0f) scrollTarget = +// 0f else if (scrollTarget < -lastHeight + 89) scrollTarget = -lastHeight + 89 +// scrollAnimation = EaseOutQuad(150, scroll, scrollTarget, false) +// scrollTime = System.currentTimeMillis() +// } else if (scrollAnimation != null && scrollAnimation!!.isFinished) scrollAnimation = +// null +// if (dragging && inputHandler.isClicked(true)) { +// dragging = false +// } +// } +// var height = 0F +// translate(0f, scroll) +// solution.solutions.forEach { +// height += 12 * 1.25f +// drawWrappedString( +// it, +// x + 50 + 20, +// y + 310f + height, +// 550 - 20 - 20, +// WHITE_60, +// 12, +// 1.25f, +// JETBRAINS_MONO +// ) +// height += NanoVGHelper.INSTANCE.getWrappedStringHeight( +// vg, it, 550F, 12F, 1.25f, JETBRAINS_MONO +// ) +// } +// height += 12 * 1.25f +// translate(0f, -scroll) +// lastHeight = height +// ScissorHelper.INSTANCE.resetScissor(vg, scissor) +// if (lastHeight > 89) { +// val scrollBarY = scroll / lastHeight * 81 +// val isMouseDown = Platform.getMousePlatform().isButtonDown(0) +// val scrollHover = inputHandler.isAreaHovered( +// (x + 50f + 20f + 530f - 14f), +// (y + 310f + 16 - scrollBarY), +// 12f, +// scrollBarLength.toInt().toFloat() +// ) +// val scrollTimePeriod = System.currentTimeMillis() - scrollTime < 1000 +// if (scrollHover && isMouseDown && !mouseWasDown) { +// yStart = inputHandler.mouseY() +// dragging = true +// } +// mouseWasDown = isMouseDown +// if (dragging) { +// scrollTarget = -(inputHandler.mouseY() - yStart) * lastHeight / 89f +// if (scrollTarget > 0f) scrollTarget = +// 0f else if (scrollTarget < -lastHeight + 89) scrollTarget = +// -lastHeight + 89f +// scrollAnimation = EaseOutQuad(150, scroll, scrollTarget, false) +// } +// NanoVGHelper.INSTANCE.drawRoundedRect( +// vg, +// (x + 50f + 20f + 530f - 14f), +// (y + 310f + 16 - scrollBarY), +// 4f, +// scrollBarLength, +// colorAnimation.getColor(scrollHover || scrollTimePeriod, dragging), +// 4f +// ) +// } +// } +// } +// } +// } +// uploadLogButton.draw(vg, x + 600 - 8 - 11 - 30f, y + 273f + 3.5f, inputHandler) +// copyLogButton.draw(vg, x + 600 - 8 - 11 - 15 - 8 - 11 - 30f, y + 273f + 3.5f, inputHandler) +// +// drawText( +// "If the solution above doesn't help, join", (windowWidth / 2f / scale) - (getTextWidth( +// "If the solution above doesn't help, join", 16, Fonts.REGULAR +// ) / 2f), y + 273 + 158 + 24 + 20, WHITE_80, 16, Fonts.REGULAR +// ) +// val discordMessageWidth = 20 + 15 + getTextWidth("https://inv.wtf/skyclient", 16, Fonts.REGULAR) +// drawSVG( +// "/assets/crashpatch/discord.svg", +// (windowWidth / 2f / scale) - (discordMessageWidth / 2), +// y + 273 + 158 + 24 + 20 + 15, +// 20, +// 20 +// ) +// drawURL( +// if (CrashPatch.isSkyclient) SKYCLIENT_DISCORD else POLYFROST_DISCORD, +// (windowWidth / 2f / scale) - (discordMessageWidth / 2) + 20 + 15, +// y + 273 + 158 + 24 + 20 + 15 + 11, +// 16, +// Fonts.REGULAR, +// inputHandler +// ) +// +// val buttonsWidth = +// returnToGameButton.width + if (type != GuiType.DISCONNECT) (getTextWidth( +// OPEN_CRASH_LOG, +// 14, +// Fonts.MEDIUM +// ) + 16 + 20) + 10 else 0f +// returnToGameButton.update((windowWidth / 2f / scale) - (buttonsWidth / 2), y + 600 - 16 - 36f, inputHandler) +// returnToGameButton.draw( +// vg, (windowWidth / 2f / scale) - (buttonsWidth / 2), y + 600 - 16 - 36f, inputHandler +// ) +// if (type != GuiType.DISCONNECT) { +// openCrashLogButton.update( +// (windowWidth / 2f / scale) - (buttonsWidth / 2) + returnToGameButton.width + 10, +// y + 600 - 16 - 36f, +// inputHandler +// ) +// openCrashLogButton.draw( +// vg, +// (windowWidth / 2f / scale) - (buttonsWidth / 2) + returnToGameButton.width + 10, +// y + 600 - 16 - 36f, +// inputHandler +// ) +// } +// } +// } +// +// private fun VG.drawURL(url: String, x: Number, y: Number, size: Int, font: Font, inputHandler: InputHandler) { +// drawText(url, x, y, HYPERLINK_BLUE, size, font) +// val length = getTextWidth(url, size, font) +// val hovered = inputHandler.isAreaHovered( +// (x.toFloat() - 2), (y.toFloat() - size.toFloat()), (length + 4), (size.toFloat() * 2 + 2) +// ) +// if (hovered || (hyperlinkAnimation != null && (hyperlinkAnimation?.isReversed == false || !hyperlinkAnimation!!.isFinished))) { +// if (!hovered && hyperlinkAnimation?.isReversed == false) { +// hyperlinkAnimation = EaseInOutQuad(100, 0f, hyperlinkAnimation!!.get(), true) +// } +// if (hyperlinkAnimation == null) { +// hyperlinkAnimation = EaseInOutQuad(100, 0f, 1f, false) +// } +// drawRect(x, y.toFloat() + size.toFloat() / 2, length, 2, ColorUtils.setAlpha(BLUE_600, (hyperlinkAnimation!!.get() * 255).toInt())) +// if (hovered && inputHandler.isClicked) { +// NetworkUtils.browseLink(url) +// } +// } else { +// hyperlinkAnimation = null +// } +// } +// +// enum class GuiType { +// INIT, NORMAL, DISCONNECT +// } +// +// companion object { +// internal var leaveWorldCrash = false +// } +//} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/crashpatch/gui/CrashGuiRewrite.kt b/src/main/kotlin/org/polyfrost/crashpatch/gui/CrashGuiRewrite.kt new file mode 100644 index 0000000..41a0ea7 --- /dev/null +++ b/src/main/kotlin/org/polyfrost/crashpatch/gui/CrashGuiRewrite.kt @@ -0,0 +1,100 @@ +package org.polyfrost.crashpatch.gui + +import net.minecraft.client.gui.GuiScreen +import net.minecraft.crash.CrashReport +import org.polyfrost.crashpatch.crashes.CrashHelper +import org.polyfrost.crashpatch.crashes.CrashScan +import org.polyfrost.crashpatch.hooks.CrashReportHook +import org.polyfrost.oneconfig.api.ui.v1.PolyUIBuilder +import org.polyfrost.oneconfig.api.ui.v1.UIManager +import org.polyfrost.polyui.PolyUI +import org.polyfrost.polyui.component.impl.Block +import org.polyfrost.polyui.component.impl.Group +import org.polyfrost.polyui.component.impl.Image +import org.polyfrost.polyui.component.impl.Text +import org.polyfrost.polyui.component.named +import org.polyfrost.polyui.component.padded +import org.polyfrost.polyui.component.setPalette +import org.polyfrost.polyui.unit.Align +import org.polyfrost.polyui.unit.Vec2 +import org.polyfrost.polyui.utils.image +import org.polyfrost.polyui.utils.rgba +import java.io.File +import java.util.function.Consumer + +class CrashGuiRewrite @JvmOverloads constructor( + private val scanText: String, + private val file: File?, + private val susThing: String, + private val type: GuiType = GuiType.NORMAL, + val throwable: Throwable? = null +) { + + @JvmOverloads + constructor(report: CrashReport, type: GuiType = GuiType.NORMAL) : this( + report.completeReport, + report.file, + (report as CrashReportHook).suspectedCrashPatchMods, + type, + report.crashCause + ) + + companion object { + var leaveWorldCrash = false + } + + private val crashScan: CrashScan? by lazy { + return@lazy CrashHelper.scanReport(scanText, type == GuiType.DISCONNECT) + .let { return@let if (it != null && it.solutions.isNotEmpty()) it else null } + } + var shouldCrash = false + + private val subtitle by lazy { + when (type) { + GuiType.INIT -> listOf(SUBTITLE_INIT_1 + (if (crashScan != null) SUBTITLE_INIT_2 else "") + SUBTITLE_INIT_3, "") + GuiType.NORMAL -> listOf(SUBTITLE_1, SUBTITLE_2) + GuiType.DISCONNECT -> listOf(SUBTITLE_DISCONNECTED, SUBTITLE_DISCONNECTED_2) + } + } + + fun create(): GuiScreen { + val builder = PolyUIBuilder.builder().blurs().backgroundColor(rgba(21, 21, 21)).atResolution(1920f, 1080f).size(650f, 600f) + + val onClose: Consumer = Consumer { _: PolyUI -> + leaveWorldCrash = false + } + + builder.onClose(onClose) + + val polyUI = builder.make( + Group( + Image("/assets/crashpatch/WarningTriangle.svg".image(Vec2(20F, 20F))).named("WarningTriangle").padded( + 0F, + 34F, + 0F, + 0F + ), + Text(if (type == GuiType.DISCONNECT) DISCONNECTED_TITLE else TITLE, fontSize = 24F, font = PolyUI.defaultFonts.medium).setPalette { text.primary }.padded(0f, 10F, 0f, 0f), + Text(subtitle[0], fontSize = 14F, font = PolyUI.defaultFonts.regular).setPalette { text.secondary }.padded(0f, 16f, 0f, 0f), + Text(subtitle[1], fontSize = 14F, font = PolyUI.defaultFonts.regular).setPalette { text.secondary }.padded(0f, 0F, 0f, 0f), + Text(if (type == GuiType.DISCONNECT) CAUSE_TEXT_DISCONNECTED else CAUSE_TEXT, fontSize = 16F, font = PolyUI.defaultFonts.regular).setPalette { text.primary }.padded(0f, 24F, 0f, 0f), + Text(susThing, fontSize = 18F, font = PolyUI.defaultFonts.semiBold).setPalette { brand.fg }.padded(0f, 8f, 0f, 0f), + //Group( + // Block( +// + // ) + //).padded(0f, 40f, 0f, 0f), + size = Vec2(650f, 600f), + alignment = Align(mode = Align.Mode.Vertical) + ), + ) + val screen = + UIManager.INSTANCE.createPolyUIScreen(polyUI, 1920f, 1080f, false, true, onClose) + polyUI.window = UIManager.INSTANCE.createWindow() + return screen as GuiScreen + } + + enum class GuiType { + INIT, NORMAL, DISCONNECT + } +} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/crashpatch/gui/constants.kt b/src/main/kotlin/org/polyfrost/crashpatch/gui/constants.kt index 91aff29..d35dbc2 100644 --- a/src/main/kotlin/org/polyfrost/crashpatch/gui/constants.kt +++ b/src/main/kotlin/org/polyfrost/crashpatch/gui/constants.kt @@ -1,20 +1,19 @@ package org.polyfrost.crashpatch.gui -import cc.polyfrost.oneconfig.renderer.font.Font -import cc.polyfrost.oneconfig.utils.color.ColorUtils +import org.polyfrost.polyui.utils.rgba -internal val GRAY_800 = ColorUtils.getColor(21, 22, 23, 255) // general background -internal val GRAY_700 = ColorUtils.getColor(34, 35, 38, 255) // log background -internal val GRAY_600 = ColorUtils.getColor(42, 44, 48, 255) // log header +internal val GRAY_800 = rgba(21, 22, 23, 1f) // general background +internal val GRAY_700 = rgba(34, 35, 38, 1f) // log background +internal val GRAY_600 = rgba(42, 44, 48, 1f) // log header -internal val WHITE_90 = ColorUtils.getColor(255, 255, 255, 229) // text -internal val WHITE_80 = ColorUtils.getColor(255, 255, 255, 204) // subtext -internal val WHITE_60 = ColorUtils.getColor(255, 255, 255, 153) // logs +internal val WHITE_90 = rgba(255, 255, 255, 229 / 255f) // text +internal val WHITE_80 = rgba(255, 255, 255, 204 / 255f) // subtext +internal val WHITE_60 = rgba(255, 255, 255, 153 / 255f) // logs -internal val BLUE_400 = ColorUtils.getColor(77, 135, 229) // yeah -internal val BLUE_600 = ColorUtils.getColor(20, 82, 204, 255) // brand.hover +internal val BLUE_400 = rgba(77, 135, 229) // yeah +internal val BLUE_600 = rgba(20, 82, 204, 1F) // brand.hover -internal val HYPERLINK_BLUE = ColorUtils.getColor(48, 129, 242) +internal val HYPERLINK_BLUE = rgba(48, 129, 242) internal val TITLE = "Uh-oh. Your game crashed!" internal val DISCONNECTED_TITLE = "Uh-oh. You were disconnected from the server!" @@ -33,6 +32,4 @@ internal val RETURN_TO_GAME = "Return to game" internal val OPEN_CRASH_LOG = "Crash log" internal val SKYCLIENT_DISCORD = "https://inv.wtf/skyclient" -internal val POLYFROST_DISCORD = "https://polyfrost.cc/discord" - -internal val JETBRAINS_MONO = Font("jetbrains-mono-regular", "/assets/crashpatch/fonts/JetBrainsMono-Regular.ttf") \ No newline at end of file +internal val POLYFROST_DISCORD = "https://polyfrost.cc/discord" \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/crashpatch/utils/GuiDisconnectedHook.kt b/src/main/kotlin/org/polyfrost/crashpatch/utils/GuiDisconnectedHook.kt index 7e9b395..456d408 100644 --- a/src/main/kotlin/org/polyfrost/crashpatch/utils/GuiDisconnectedHook.kt +++ b/src/main/kotlin/org/polyfrost/crashpatch/utils/GuiDisconnectedHook.kt @@ -5,9 +5,9 @@ import org.polyfrost.crashpatch.mixin.AccessorGuiDisconnected import net.minecraft.client.gui.GuiDisconnected import net.minecraft.client.gui.GuiScreen import org.spongepowered.asm.mixin.injection.callback.CallbackInfo -import cc.polyfrost.oneconfig.utils.dsl.mc import org.polyfrost.crashpatch.config.CrashPatchConfig -import org.polyfrost.crashpatch.gui.CrashGui +import org.polyfrost.crashpatch.gui.CrashGuiRewrite +import org.polyfrost.crashpatch.mc object GuiDisconnectedHook { fun onGUIDisplay(i: GuiScreen?, ci: CallbackInfo) { @@ -16,7 +16,7 @@ object GuiDisconnectedHook { val scan = scanReport(gui.message.formattedText, true) if (scan != null && scan.solutions.size > 1) { ci.cancel() - mc.displayGuiScreen(CrashGui(gui.message.formattedText, null, gui.reason, CrashGui.GuiType.DISCONNECT)) + mc.displayGuiScreen(CrashGuiRewrite(gui.message.formattedText, null, gui.reason, CrashGuiRewrite.GuiType.DISCONNECT).create()) } } } diff --git a/src/main/kotlin/org/polyfrost/crashpatch/utils/InternetUtils.kt b/src/main/kotlin/org/polyfrost/crashpatch/utils/InternetUtils.kt index 2d14210..7d5cf58 100644 --- a/src/main/kotlin/org/polyfrost/crashpatch/utils/InternetUtils.kt +++ b/src/main/kotlin/org/polyfrost/crashpatch/utils/InternetUtils.kt @@ -14,7 +14,7 @@ import javax.net.ssl.HttpsURLConnection object InternetUtils { - private val sessionIdRegex = Regex("((Session ID is|--accessToken|Your new API key is) (?:\\S+))") + private val sessionIdRegex = Regex("((Session ID is|--accessToken|Your new API key is) (\\S+))") fun upload(text: String): String { val log = Log(text.replace(sessionIdRegex, "[SENSITIVE INFORMATION]")) return when (CrashPatchConfig.crashLogUploadMethod) {