From 460bc5f74c6ad23ced624e2a29ed26473319c64d Mon Sep 17 00:00:00 2001 From: Gary Bryson Luis Jr Date: Thu, 4 Aug 2022 15:26:40 +0800 Subject: [PATCH] rework detect final --- README.md | 2 +- .../CrappyLauncherError.java | 2 +- .../PreventCrappyLauncher.java | 23 +++++++++++++++---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 460aa2d..89152f4 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,6 @@ A mod, a mod whose use you know by heart. -Check `retro` branch for `<= 1.12.2`, `modern` branch (not done yet) for `>= 1.13`. +Check `retro` branch for `<= 1.12.2`, `modern` branch for `>= 1.13`. Everything licensed under [Mozilla Public License 2.0](./LICENSE). diff --git a/src/main/java/gblodb/preventCrappyLauncher/CrappyLauncherError.java b/src/main/java/gblodb/preventCrappyLauncher/CrappyLauncherError.java index 726d146..ef584ee 100644 --- a/src/main/java/gblodb/preventCrappyLauncher/CrappyLauncherError.java +++ b/src/main/java/gblodb/preventCrappyLauncher/CrappyLauncherError.java @@ -1,6 +1,6 @@ package gblodb.preventCrappyLauncher; -public class CrappyLauncherError extends RuntimeException { +public class CrappyLauncherError extends Error { public CrappyLauncherError(String errorMessage) { super(errorMessage); } diff --git a/src/main/java/gblodb/preventCrappyLauncher/PreventCrappyLauncher.java b/src/main/java/gblodb/preventCrappyLauncher/PreventCrappyLauncher.java index cdf9195..1e6bc6a 100644 --- a/src/main/java/gblodb/preventCrappyLauncher/PreventCrappyLauncher.java +++ b/src/main/java/gblodb/preventCrappyLauncher/PreventCrappyLauncher.java @@ -1,6 +1,6 @@ package gblodb.preventCrappyLauncher; -import java.io.File; +import java.io.*; import java.util.List; import net.minecraft.launchwrapper.ITweaker; import net.minecraft.launchwrapper.LaunchClassLoader; @@ -8,10 +8,25 @@ public class PreventCrappyLauncher implements ITweaker { @Override public void acceptOptions(List args, File gameDir, File assetsDir, String profile) throws CrappyLauncherError { - File pclDir = new File(gameDir.getPath() + "\\PCL"); - if (pclDir.exists()) { - throw new CrappyLauncherError("You're using an unsupported launcher."); + int count = 0; + + if (!System.getProperty("os.name").toLowerCase().contains("win")) return; + + try { + String line; + String cmd = System.getenv("windir") + "\\system32\\" + "tasklist.exe" + " /FO csv /FI \"WINDOWTITLE eq Plain Craft Launcher 2\u3000\""; + Process pr = new ProcessBuilder(cmd).start(); + SequenceInputStream sis = new SequenceInputStream(pr.getInputStream(), pr.getErrorStream()); + InputStreamReader inst = new InputStreamReader(sis); + BufferedReader br = new BufferedReader(inst); + while ((line = br.readLine()) != null) { + if (line.startsWith("\"")) count++; + } + } catch (Exception ignored) { + // lol } + + if (count > 1) throw new CrappyLauncherError("You're using an unsupported launcher."); } @Override