diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index 6cfbb987..9d6f916b 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -1,5 +1,5 @@ -def mainClassName = "LaunchServer" -def mainAgentName = "StarterAgent" +def mainClassName = "ru.gravit.launchserver.LaunchServer" +def mainAgentName = "ru.gravit.launchserver.StarterAgent" repositories { maven { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 8b95acef..be52d0b1 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -382,7 +382,7 @@ public LaunchServer(Path dir, boolean portable) throws IOException, InvalidKeySp // pre init modules modulesManager = new ModulesManager(this); - modulesManager.autoload(); + modulesManager.autoload(dir.resolve("modules")); modulesManager.preInitModules(); // Read LaunchServer config diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/ProguardConf.java b/LaunchServer/src/main/java/ru/gravit/launchserver/ProguardConf.java index ed97e009..acfc311a 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/ProguardConf.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/ProguardConf.java @@ -39,7 +39,7 @@ public ProguardConf(LaunchServer srv) { words = proguard.resolve("random.pro"); confStrs = new HashSet<>(); prepare(false); - confStrs.add(readConf()); + confStrs.add("@".concat(config.toString())); if (this.srv.config.genMappings) confStrs.add("-printmapping \'" + mappings.toFile().getName() + "\'"); confStrs.add("-obfuscationdictionary \'" + words.toFile().getName() + "\'"); confStrs.add("-classobfuscationdictionary \'" + words.toFile().getName() + "\'"); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java index 8f3390d1..77d5a0cf 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java @@ -24,12 +24,12 @@ public JAConfigurator(Class configclass) throws NotFoundException { } public void addModuleClass(String fullName) { - body.append("Module mod"); + body.append("ru.gravit.launcher.modules.Module mod"); body.append(autoincrement); body.append(" = new "); body.append(fullName); body.append("();"); - body.append("Launcher.modulesManager.registerModule( mod"); + body.append("ru.gravit.launcher.Launcher.modulesManager.registerModule( mod"); body.append(autoincrement); body.append(" , true );"); autoincrement++; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ResponseThread.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ResponseThread.java index 901929bd..073d866c 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ResponseThread.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ResponseThread.java @@ -49,6 +49,10 @@ private Handshake readHandshake(HInput input, HOutput output) throws IOException session = 0; legacy = true; } + else if (magicNumber == Launcher.PROTOCOL_MAGIC_LEGACY - 2) { // Previous launcher protocol + session = 0; + legacy = true; + } else if (magicNumber == Launcher.PROTOCOL_MAGIC_LEGACY){ } else diff --git a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/proguard.cfg b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/proguard.cfg index 257099fb..6dfb5ab8 100644 --- a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/proguard.cfg +++ b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/proguard.cfg @@ -1,7 +1,7 @@ -libraryjars '/lib/rt.jar' -libraryjars '/lib/jce.jar' -libraryjars '/lib/ext/nashorn.jar' --injars ../Launcher.jar(!META-INF/versions/**) +-injars ../Launcher.jar -outjars ../Launcher-obf.jar -keepattributes SourceFile,LineNumberTable -renamesourcefileattribute Source @@ -15,7 +15,7 @@ -forceprocessing -overloadaggressively --repackageclasses 'launcher' +-repackageclasses 'ru.gravit.launcher' -keep class ru.zaxar163.* -keepattributes SourceFile,LineNumberTable,*Annotation* -renamesourcefileattribute SourceFile @@ -32,15 +32,15 @@ *; } --keepclassmembers @LauncherAPI class ** { +-keepclassmembers @ru.gravit.launcher.LauncherAPI class ** { ; ; } -keepclassmembers class ** { - @LauncherAPI + @ru.gravit.launcher.LauncherAPI ; - @LauncherAPI + @ru.gravit.launcher.LauncherAPI ; } diff --git a/Launcher/build.gradle b/Launcher/build.gradle index ff2c86c2..1614eafd 100644 --- a/Launcher/build.gradle +++ b/Launcher/build.gradle @@ -1,5 +1,5 @@ -String mainClassName = "LauncherEngine" -String mainAgentName = "LauncherAgent" +String mainClassName = "ru.gravit.launcher.LauncherEngine" +String mainAgentName = "ru.gravit.launcher.LauncherAgent" repositories { diff --git a/Launcher/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java b/Launcher/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java index 8df5451b..ce08eec1 100644 --- a/Launcher/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java +++ b/Launcher/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java @@ -171,7 +171,9 @@ public GameProfile hasJoinedServer(GameProfile profile, String serverID) throws public GameProfile hasJoinedServer(GameProfile profile, String serverID, InetAddress address) throws AuthenticationUnavailableException { return hasJoinedServer(profile, serverID); } - + public YggdrasilAuthenticationService getAuthenticationService() { + return (YggdrasilAuthenticationService)super.getAuthenticationService(); + } @Override public void joinServer(GameProfile profile, String accessToken, String serverID) throws AuthenticationException { if (!ClientLauncher.isLaunched()) diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index 66254ce2..3be034ab 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -147,8 +147,6 @@ public static void addLauncherClassBindings(Map bindings) { } public static void main(String... args) throws Throwable { - if(System.getProperty("log4j.configurationFile") == null) - System.setProperty("log4j.configurationFile", "ru/gravit/launcher/log4j2.xml"); JVMHelper.verifySystemProperties(Launcher.class, true); LogHelper.printVersion("Launcher"); // Start Launcher @@ -172,10 +170,11 @@ private LauncherEngine() { } @LauncherAPI - public Object loadScript(URL url) throws IOException, ScriptException { + public Object loadScript(String path) throws IOException, ScriptException { + URL url = Launcher.getResourceURL(path); LogHelper.debug("Loading script: '%s'", url); try (BufferedReader reader = IOHelper.newReader(url)) { - return engine.eval(reader); + return engine.eval(reader,engine.getBindings(ScriptContext.ENGINE_SCOPE)); } } @@ -198,7 +197,10 @@ public void start(String... args) throws Throwable { throw new IllegalStateException("Launcher has been already started"); Launcher.modulesManager.initModules(); // Load init.js script - loadScript(Launcher.getResourceURL(Launcher.INIT_SCRIPT_FILE)); + loadScript(Launcher.API_SCRIPT_FILE); + loadScript(Launcher.INIT_SCRIPT_FILE); + loadScript("config.js"); + loadScript("dialog/dialog.js"); LogHelper.info("Invoking start() function"); Invocable invoker = (Invocable) engine; if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) { diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/JSApplication.java b/Launcher/src/main/java/ru/gravit/launcher/client/JSApplication.java index 77697feb..6d209dda 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/JSApplication.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/JSApplication.java @@ -9,11 +9,12 @@ @SuppressWarnings("AbstractClassNeverImplemented") public abstract class JSApplication extends Application { private static final AtomicReference INSTANCE = new AtomicReference<>(); - + @LauncherAPI public static JSApplication getInstance() { return INSTANCE.get(); } + @SuppressWarnings("ConstructorNotProtectedInAbstractClass") public JSApplication() { INSTANCE.set(this); diff --git a/libLauncher/build.gradle b/libLauncher/build.gradle index e8006282..6a5c5d66 100644 --- a/libLauncher/build.gradle +++ b/libLauncher/build.gradle @@ -6,5 +6,4 @@ compileOnly 'org.javassist:javassist:3.23.1-GA' compile files('../compat/authlib/authlib-clean.jar') compile 'com.eclipsesource.minimal-json:minimal-json:0.9.4' - compile group: 'org.eclipse.jetty.websocket', name: 'websocket-client', version: '9.4.12.v20180830' } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java index a2532888..b94fe521 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java @@ -40,6 +40,8 @@ public final class Launcher { public static final String CONFIG_FILE = "config.bin"; @LauncherAPI public static final String INIT_SCRIPT_FILE = "init.js"; + @LauncherAPI + public static final String API_SCRIPT_FILE = "engine/api.js"; private static final Pattern UUID_PATTERN = Pattern.compile("-", Pattern.LITERAL); diff --git a/libLauncher/src/main/java/ru/gravit/utils/websocket/MessageInterface.java b/libLauncher/src/main/java/ru/gravit/utils/websocket/MessageInterface.java deleted file mode 100644 index 0502814b..00000000 --- a/libLauncher/src/main/java/ru/gravit/utils/websocket/MessageInterface.java +++ /dev/null @@ -1,8 +0,0 @@ -package ru.gravit.utils.websocket; - -import ru.gravit.launcher.serialize.HInput; - -@FunctionalInterface -public interface MessageInterface { - void request(HInput input); -} diff --git a/libLauncher/src/main/java/ru/gravit/utils/websocket/WebSocketClient.java b/libLauncher/src/main/java/ru/gravit/utils/websocket/WebSocketClient.java deleted file mode 100644 index 70c58a72..00000000 --- a/libLauncher/src/main/java/ru/gravit/utils/websocket/WebSocketClient.java +++ /dev/null @@ -1,67 +0,0 @@ -package ru.gravit.utils.websocket; - -import java.io.BufferedInputStream; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.ByteBuffer; -import java.util.concurrent.*; - -import jdk.nashorn.internal.ir.RuntimeNode; -import org.eclipse.jetty.websocket.api.Session; -import org.eclipse.jetty.websocket.api.StatusCode; -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose; -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect; -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; -import org.eclipse.jetty.websocket.api.annotations.WebSocket; -import ru.gravit.launcher.Launcher; -import ru.gravit.launcher.serialize.HInput; -import ru.gravit.launcher.serialize.HOutput; -import ru.gravit.utils.helper.IOHelper; - -/** - * Basic Echo Client Socket - */ -@WebSocket(maxTextMessageSize = 64 * 1024) -public class WebSocketClient -{ - private final CountDownLatch closeLatch; - @SuppressWarnings("unused") - private Session session; - private final MessageInterface adapter; - public WebSocketClient(MessageInterface adapter) - { - this.closeLatch = new CountDownLatch(1); - this.adapter = adapter; - } - - public boolean awaitClose(int duration, TimeUnit unit) throws InterruptedException - { - return this.closeLatch.await(duration,unit); - } - - @OnWebSocketClose - public void onClose(int statusCode, String reason) - { - System.out.printf("Connection closed: %d - %s%n",statusCode,reason); - this.session = null; - this.closeLatch.countDown(); // trigger latch - } - - @OnWebSocketConnect - public void onConnect(Session session) - { - System.out.printf("Got connect: %s%n",session); - this.session = session; - } - public void request(ByteBuffer buffer) throws IOException { - session.getRemote().sendBytes(buffer); - } - @OnWebSocketMessage - public void onMessage(String msg) throws IOException { - byte[] bytes = msg.getBytes(); - InputStream stream = new ByteArrayInputStream(bytes); - HInput input = new HInput(stream); - adapter.request(input); - } -} diff --git a/modules/NeverDecomp/src/main/java/ru/gravit/launcher/neverdecomp/NeverDecompModule.java b/modules/NeverDecomp/src/main/java/ru/gravit/launcher/neverdecomp/NeverDecompModule.java index 8da8f20f..1304b4ff 100644 --- a/modules/NeverDecomp/src/main/java/ru/gravit/launcher/neverdecomp/NeverDecompModule.java +++ b/modules/NeverDecomp/src/main/java/ru/gravit/launcher/neverdecomp/NeverDecompModule.java @@ -23,6 +23,11 @@ public LauncherVersion getVersion() { return new LauncherVersion(1, 0, 1, 2); } + @Override + public int getPriority() { + return 1; + } + @Override public void init(ModuleContext context1) { if (context1.getType().equals(ModuleContext.Type.LAUNCHSERVER)) {