Skip to content

Commit

Permalink
rework detect final
Browse files Browse the repository at this point in the history
  • Loading branch information
GBLodb committed Aug 4, 2022
1 parent c3b4000 commit 460bc5f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package gblodb.preventCrappyLauncher;

public class CrappyLauncherError extends RuntimeException {
public class CrappyLauncherError extends Error {
public CrappyLauncherError(String errorMessage) {
super(errorMessage);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
package gblodb.preventCrappyLauncher;

import java.io.File;
import java.io.*;
import java.util.List;
import net.minecraft.launchwrapper.ITweaker;
import net.minecraft.launchwrapper.LaunchClassLoader;

public class PreventCrappyLauncher implements ITweaker {
@Override
public void acceptOptions(List<String> 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
Expand Down

0 comments on commit 460bc5f

Please sign in to comment.