From 42c27b8845649c4a45bc3463726ba1733a59e3f5 Mon Sep 17 00:00:00 2001 From: tterrag Date: Thu, 25 Apr 2019 15:52:02 -0400 Subject: [PATCH] Change default username to 'Dev', add ability to replace '#' with randomized numbers --- .../minecraftforge/userdev/LaunchTesting.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/userdev/java/net/minecraftforge/userdev/LaunchTesting.java b/src/userdev/java/net/minecraftforge/userdev/LaunchTesting.java index 622e5b1a0..037a2a165 100644 --- a/src/userdev/java/net/minecraftforge/userdev/LaunchTesting.java +++ b/src/userdev/java/net/minecraftforge/userdev/LaunchTesting.java @@ -31,10 +31,13 @@ import java.lang.reflect.Field; import java.net.Proxy; import java.util.Arrays; import java.util.Locale; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import org.apache.logging.log4j.LogManager; public class LaunchTesting -{ +{ public static void main(String... args) throws InterruptedException { final String markerselection = System.getProperty("forge.logging.markers", ""); @@ -68,7 +71,18 @@ public class LaunchTesting if (!lst.hasValue("accessToken")) { if (!login(lst)) { - lst.putLazy("username", "Test"); + String username = lst.get("username"); + if (username != null) { // Replace '#' placeholders with random numbers + Matcher m = Pattern.compile("#+").matcher(username); + StringBuffer replaced = new StringBuffer(); + while (m.find()) { + m.appendReplacement(replaced, getRandomNumbers(m.group().length())); + } + m.appendTail(replaced); + lst.put("username", replaced.toString()); + } else { + lst.putLazy("username", "Dev"); + } lst.put("accessToken", "DONT_CRASH"); lst.put("userProperties", "{}"); } @@ -85,6 +99,11 @@ public class LaunchTesting Thread.sleep(10000);// Why do we have this? -Lex 03/06/19 } + private static String getRandomNumbers(int length) + { // Generate a time-based random number, to mimic how n.m.client.Main works + return Long.toString(System.nanoTime() % (int) Math.pow(10, length)); + } + private static void hackNatives() { String paths = System.getProperty("java.library.path");