diff --git a/src/main/java/net/raphimc/viaproxy/ViaProxy.java b/src/main/java/net/raphimc/viaproxy/ViaProxy.java index 51bb476..4fd189f 100644 --- a/src/main/java/net/raphimc/viaproxy/ViaProxy.java +++ b/src/main/java/net/raphimc/viaproxy/ViaProxy.java @@ -84,13 +84,14 @@ public class ViaProxy { } try { transformerManager.hookInstrumentation(Agents.getInstrumentation()); - injectedMain("Runtime Agent", args); } catch (Throwable t) { final InjectionClassLoader injectionClassLoader = new InjectionClassLoader(transformerManager, ClassLoaders.getSystemClassPath()); injectionClassLoader.setPriority(EnumLoaderPriority.PARENT_FIRST); Thread.currentThread().setContextClassLoader(injectionClassLoader); Methods.invoke(null, Methods.getDeclaredMethod(injectionClassLoader.loadClass(ViaProxy.class.getName()), "injectedMain", String.class, String[].class), "Injection ClassLoader", args); + return; } + injectedMain("Runtime Agent", args); } public static void injectedMain(final String injectionMethod, final String[] args) throws InterruptedException, IOException { diff --git a/src/main/java/net/raphimc/viaproxy/cli/options/Options.java b/src/main/java/net/raphimc/viaproxy/cli/options/Options.java index e594cb1..8d98efa 100644 --- a/src/main/java/net/raphimc/viaproxy/cli/options/Options.java +++ b/src/main/java/net/raphimc/viaproxy/cli/options/Options.java @@ -85,49 +85,49 @@ public class Options { final OptionSet options; try { options = parser.parse(args); + + if (options.has(help)) { + parser.formatHelpWith(new BetterHelpFormatter()); + parser.printHelpOn(Logger.SYSOUT); + System.exit(1); + } + + BIND_ADDRESS = options.valueOf(bindAddress); + BIND_PORT = options.valueOf(bindPort); + SRV_MODE = options.has(srvMode); + INTERNAL_SRV_MODE = options.has(iSrvMode); + ONLINE_MODE = options.has(onlineMode); + CONNECT_ADDRESS = options.valueOf(connectAddress); + PROTOCOL_VERSION = options.valueOf(version); + if (options.has(connectPort)) { + CONNECT_PORT = options.valueOf(connectPort); + } else { + CONNECT_PORT = PluginManager.EVENT_MANAGER.call(new GetDefaultPortEvent(PROTOCOL_VERSION, 25565)).getDefaultPort(); + } + COMPRESSION_THRESHOLD = options.valueOf(compressionThreshold); + OPENAUTHMOD_AUTH = options.has(openAuthModAuth); + BETACRAFT_AUTH = options.has(betaCraftAuth); + if (options.has(resourcePackUrl)) { + RESOURCE_PACK_URL = options.valueOf(resourcePackUrl); + } + if (options.has(proxyUrl)) { + try { + PROXY_URL = new URI(options.valueOf(proxyUrl)); + } catch (URISyntaxException e) { + Logger.LOGGER.error("Invalid proxy url: " + options.valueOf(proxyUrl)); + Logger.LOGGER.error("Proxy url format: type://address:port or type://username:password@address:port"); + System.exit(1); + } + } + SERVER_HAPROXY_PROTOCOL = options.has(serverHaProxyProtocol); + LEGACY_CLIENT_PASSTHROUGH = options.has(legacyClientPassthrough); + PluginManager.EVENT_MANAGER.call(new PostOptionsParseEvent(options)); } catch (OptionException e) { Logger.LOGGER.error("Error parsing options: " + e.getMessage()); parser.formatHelpWith(new BetterHelpFormatter()); parser.printHelpOn(Logger.SYSOUT); System.exit(1); - return; } - if (options.has(help)) { - parser.formatHelpWith(new BetterHelpFormatter()); - parser.printHelpOn(Logger.SYSOUT); - System.exit(1); - } - - BIND_ADDRESS = options.valueOf(bindAddress); - BIND_PORT = options.valueOf(bindPort); - SRV_MODE = options.has(srvMode); - INTERNAL_SRV_MODE = options.has(iSrvMode); - ONLINE_MODE = options.has(onlineMode); - CONNECT_ADDRESS = options.valueOf(connectAddress); - PROTOCOL_VERSION = options.valueOf(version); - if (options.has(connectPort)) { - CONNECT_PORT = options.valueOf(connectPort); - } else { - CONNECT_PORT = PluginManager.EVENT_MANAGER.call(new GetDefaultPortEvent(PROTOCOL_VERSION, 25565)).getDefaultPort(); - } - COMPRESSION_THRESHOLD = options.valueOf(compressionThreshold); - OPENAUTHMOD_AUTH = options.has(openAuthModAuth); - BETACRAFT_AUTH = options.has(betaCraftAuth); - if (options.has(resourcePackUrl)) { - RESOURCE_PACK_URL = options.valueOf(resourcePackUrl); - } - if (options.has(proxyUrl)) { - try { - PROXY_URL = new URI(options.valueOf(proxyUrl)); - } catch (URISyntaxException e) { - Logger.LOGGER.error("Invalid proxy url: " + options.valueOf(proxyUrl)); - Logger.LOGGER.error("Proxy url format: type://address:port or type://username:password@address:port"); - System.exit(1); - } - } - SERVER_HAPROXY_PROTOCOL = options.has(serverHaProxyProtocol); - LEGACY_CLIENT_PASSTHROUGH = options.has(legacyClientPassthrough); - PluginManager.EVENT_MANAGER.call(new PostOptionsParseEvent(options)); } } diff --git a/src/main/java/net/raphimc/viaproxy/cli/options/VersionEnumConverter.java b/src/main/java/net/raphimc/viaproxy/cli/options/VersionEnumConverter.java index c75c4a5..af89783 100644 --- a/src/main/java/net/raphimc/viaproxy/cli/options/VersionEnumConverter.java +++ b/src/main/java/net/raphimc/viaproxy/cli/options/VersionEnumConverter.java @@ -28,6 +28,10 @@ public class VersionEnumConverter implements ValueConverter { for (VersionEnum version : VersionEnum.getAllVersions()) { if (version.getName().equalsIgnoreCase(s)) return version; } + for (VersionEnum version : VersionEnum.getAllVersions()) { + if (version.getProtocol().getIncludedVersions().contains(s)) return version; + } + throw new ValueConversionException("Unable to find version '" + s + "'"); }