add keycodes & fix launcher & remove some useless code

This commit is contained in:
Tungstend 2022-10-22 13:52:24 +08:00
parent 433c3dc5b6
commit 6b9fa7f410
5 changed files with 189 additions and 117 deletions

View File

@ -1,5 +1,7 @@
package com.tungsten.fclcore.game;
import com.tungsten.fclauncher.FCLConfig;
import org.jetbrains.annotations.NotNull;
import java.io.File;
@ -26,12 +28,9 @@ public class LaunchOptions implements Serializable {
private Integer height;
private boolean fullscreen;
private String serverIp;
private Proxy proxy;
private String proxyUser;
private String proxyPass;
private boolean noGeneratedJVMArgs;
private ProcessPriority processPriority = ProcessPriority.NORMAL;
private boolean daemon;
private FCLConfig.Renderer renderer;
/**
* The game directory
@ -142,27 +141,6 @@ public class LaunchOptions implements Serializable {
return serverIp;
}
/**
* Proxy settings
*/
public Proxy getProxy() {
return proxy;
}
/**
* The user name of the proxy, optional.
*/
public String getProxyUser() {
return proxyUser;
}
/**
* The password of the proxy, optional
*/
public String getProxyPass() {
return proxyPass;
}
/**
* Prevent game launcher from generating default JVM arguments like max memory.
*/
@ -178,10 +156,10 @@ public class LaunchOptions implements Serializable {
}
/**
* Will launcher keeps alive after game launched or not.
* Renderer
*/
public boolean isDaemon() {
return daemon;
public FCLConfig.Renderer getRenderer() {
return renderer;
}
public static class Builder {
@ -298,27 +276,6 @@ public class LaunchOptions implements Serializable {
return options.serverIp;
}
/**
* Proxy settings
*/
public Proxy getProxy() {
return options.proxy;
}
/**
* The user name of the proxy, optional.
*/
public String getProxyUser() {
return options.proxyUser;
}
/**
* The password of the proxy, optional
*/
public String getProxyPass() {
return options.proxyPass;
}
/**
* Prevent game launcher from generating default JVM arguments like max memory.
*/
@ -326,8 +283,18 @@ public class LaunchOptions implements Serializable {
return options.noGeneratedJVMArgs;
}
public boolean isDaemon() {
return options.daemon;
/**
* Process priority
*/
public ProcessPriority getProcessPriority() {
return options.processPriority;
}
/**
* Renderer
*/
public FCLConfig.Renderer getRenderer() {
return options.renderer;
}
public Builder setGameDir(File gameDir) {
@ -408,21 +375,6 @@ public class LaunchOptions implements Serializable {
return this;
}
public Builder setProxy(Proxy proxy) {
options.proxy = proxy;
return this;
}
public Builder setProxyUser(String proxyUser) {
options.proxyUser = proxyUser;
return this;
}
public Builder setProxyPass(String proxyPass) {
options.proxyPass = proxyPass;
return this;
}
public Builder setNoGeneratedJVMArgs(boolean noGeneratedJVMArgs) {
options.noGeneratedJVMArgs = noGeneratedJVMArgs;
return this;
@ -433,8 +385,8 @@ public class LaunchOptions implements Serializable {
return this;
}
public Builder setDaemon(boolean daemon) {
options.daemon = daemon;
public Builder setRenderer(FCLConfig.Renderer renderer) {
options.renderer = renderer;
return this;
}

View File

@ -4,10 +4,15 @@ import static com.tungsten.fclcore.util.Lang.mapOf;
import static com.tungsten.fclcore.util.Pair.pair;
import android.content.Context;
import android.view.Surface;
import com.tungsten.fclauncher.FCLConfig;
import com.tungsten.fclauncher.FCLauncher;
import com.tungsten.fclauncher.bridge.FCLBridge;
import com.tungsten.fclauncher.bridge.FCLBridgeCallback;
import com.tungsten.fclauncher.utils.Architecture;
import com.tungsten.fclcore.auth.AuthInfo;
import com.tungsten.fclcore.constant.FCLPath;
import com.tungsten.fclcore.game.Argument;
import com.tungsten.fclcore.game.Arguments;
import com.tungsten.fclcore.game.GameRepository;
@ -21,20 +26,18 @@ import com.tungsten.fclcore.util.platform.CommandBuilder;
import com.tungsten.fclcore.util.versioning.VersionNumber;
import java.io.*;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.nio.file.Path;
import java.util.*;
import java.util.function.Supplier;
public class DefaultLauncher extends Launcher {
public DefaultLauncher(Context context, GameRepository repository, Version version, AuthInfo authInfo, LaunchOptions options) {
this(context, repository, version, authInfo, options, true);
public DefaultLauncher(Context context, Surface surface, GameRepository repository, Version version, AuthInfo authInfo, LaunchOptions options) {
super(context, surface, repository, version, authInfo, options);
}
public DefaultLauncher(Context context, GameRepository repository, Version version, AuthInfo authInfo, LaunchOptions options, boolean daemon) {
super(context, repository, version, authInfo, options, daemon);
public DefaultLauncher(Context context, Surface surface, GameRepository repository, Version version, AuthInfo authInfo, LaunchOptions options, FCLBridgeCallback callback) {
super(context, surface, repository, version, authInfo, options, callback);
}
private CommandBuilder generateCommandLine() throws IOException {
@ -117,24 +120,6 @@ public class DefaultLauncher extends Launcher {
res.addDefault("-Dlwjgl.platform=", "FCL");
res.addDefault("-Dorg.lwjgl.opengl.libname=", "${gl_lib_name}");
Proxy proxy = options.getProxy();
if (proxy != null && StringUtils.isBlank(options.getProxyUser()) && StringUtils.isBlank(options.getProxyPass())) {
InetSocketAddress address = (InetSocketAddress) options.getProxy().address();
if (address != null) {
String host = address.getHostString();
int port = address.getPort();
if (proxy.type() == Proxy.Type.HTTP) {
res.addDefault("-Dhttp.proxyHost=", host);
res.addDefault("-Dhttp.proxyPort=", String.valueOf(port));
res.addDefault("-Dhttps.proxyHost=", host);
res.addDefault("-Dhttps.proxyPort=", String.valueOf(port));
} else if (proxy.type() == Proxy.Type.SOCKS) {
res.addDefault("-DsocksProxyHost=", host);
res.addDefault("-DsocksProxyPort=", String.valueOf(port));
}
}
}
List<String> classpath = repository.getClasspath(version);
File jar = repository.getVersionJar(version);
@ -182,22 +167,6 @@ public class DefaultLauncher extends Launcher {
if (options.isFullscreen())
res.add("--fullscreen");
if (options.getProxy() != null && options.getProxy().type() == Proxy.Type.SOCKS) {
InetSocketAddress address = (InetSocketAddress) options.getProxy().address();
if (address != null) {
res.add("--proxyHost");
res.add(address.getHostString());
res.add("--proxyPort");
res.add(String.valueOf(address.getPort()));
if (StringUtils.isNotBlank(options.getProxyUser()) && StringUtils.isNotBlank(options.getProxyPass())) {
res.add("--proxyUser");
res.add(options.getProxyUser());
res.add("--proxyPass");
res.add(options.getProxyPass());
}
}
}
res.addAllWithoutParsing(Arguments.parseStringArguments(options.getGameArguments(), configuration));
res.removeIf(it -> getForbiddens().containsKey(it) && getForbiddens().get(it).get());
@ -300,7 +269,17 @@ public class DefaultLauncher extends Launcher {
if (isUsingLog4j()) {
extractLog4jConfigurationFile();
}
return null;
String[] finalArgs = rawCommandLine.toArray(new String[0]);
FCLConfig config = new FCLConfig(context,
surface,
FCLPath.LOG_DIR,
options.getJava().getVersion() == 8 ? FCLPath.JAVA_8_PATH : FCLPath.JAVA_17_PATH,
repository.getRunDirectory(version.getId()).getAbsolutePath(),
options.getRenderer(),
finalArgs,
callback);
return FCLauncher.launchMinecraft(config);
}
}

View File

@ -1,8 +1,10 @@
package com.tungsten.fclcore.launch;
import android.content.Context;
import android.view.Surface;
import com.tungsten.fclauncher.bridge.FCLBridge;
import com.tungsten.fclauncher.bridge.FCLBridgeCallback;
import com.tungsten.fclcore.auth.AuthInfo;
import com.tungsten.fclcore.game.GameRepository;
import com.tungsten.fclcore.game.LaunchOptions;
@ -13,23 +15,25 @@ import java.io.IOException;
public abstract class Launcher {
protected final Context context;
protected final Surface surface;
protected final GameRepository repository;
protected final Version version;
protected final AuthInfo authInfo;
protected final LaunchOptions options;
protected final boolean daemon;
protected final FCLBridgeCallback callback;
public Launcher(Context context, GameRepository repository, Version version, AuthInfo authInfo, LaunchOptions options) {
this(context, repository, version, authInfo, options, true);
public Launcher(Context context, Surface surface, GameRepository repository, Version version, AuthInfo authInfo, LaunchOptions options) {
this(context, surface, repository, version, authInfo, options, null);
}
public Launcher(Context context, GameRepository repository, Version version, AuthInfo authInfo, LaunchOptions options, boolean daemon) {
public Launcher(Context context, Surface surface, GameRepository repository, Version version, AuthInfo authInfo, LaunchOptions options, FCLBridgeCallback callback) {
this.context = context;
this.surface = surface;
this.repository = repository;
this.version = version;
this.authInfo = authInfo;
this.options = options;
this.daemon = daemon;
this.callback = callback;
}
public abstract FCLBridge launch() throws IOException, InterruptedException;

View File

@ -0,0 +1,133 @@
package com.tungsten.fclauncher;
public final class FCLKeycodes {
public static final int KEY_RESERVED = 0;
public static final int KEY_ESC = 1;
public static final int KEY_1 = 2;
public static final int KEY_2 = 3;
public static final int KEY_3 = 4;
public static final int KEY_4 = 5;
public static final int KEY_5 = 6;
public static final int KEY_6 = 7;
public static final int KEY_7 = 8;
public static final int KEY_8 = 9;
public static final int KEY_9 = 10;
public static final int KEY_0 = 11;
public static final int KEY_MINUS = 12;
public static final int KEY_EQUAL = 13;
public static final int KEY_BACKSPACE = 14;
public static final int KEY_TAB = 15;
public static final int KEY_Q = 16;
public static final int KEY_W = 17;
public static final int KEY_E = 18;
public static final int KEY_R = 19;
public static final int KEY_T = 20;
public static final int KEY_Y = 21;
public static final int KEY_U = 22;
public static final int KEY_I = 23;
public static final int KEY_O = 24;
public static final int KEY_P = 25;
public static final int KEY_LEFTBRACE = 26;
public static final int KEY_RIGHTBRACE = 27;
public static final int KEY_ENTER = 28;
public static final int KEY_LEFTCTRL = 29;
public static final int KEY_A = 30;
public static final int KEY_S = 31;
public static final int KEY_D = 32;
public static final int KEY_F = 33;
public static final int KEY_G = 34;
public static final int KEY_H = 35;
public static final int KEY_J = 36;
public static final int KEY_K = 37;
public static final int KEY_L = 38;
public static final int KEY_SEMICOLON = 39;
public static final int KEY_APOSTROPHE = 40;
public static final int KEY_GRAVE = 41;
public static final int KEY_LEFTSHIFT = 42;
public static final int KEY_BACKSLASH = 43;
public static final int KEY_Z = 44;
public static final int KEY_X = 45;
public static final int KEY_C = 46;
public static final int KEY_V = 47;
public static final int KEY_B = 48;
public static final int KEY_N = 49;
public static final int KEY_M = 50;
public static final int KEY_COMMA = 51;
public static final int KEY_DOT = 52;
public static final int KEY_SLASH = 53;
public static final int KEY_RIGHTSHIFT = 54;
public static final int KEY_KPASTERISK = 55;
public static final int KEY_LEFTALT = 56;
public static final int KEY_SPACE = 57;
public static final int KEY_CAPSLOCK = 58;
public static final int KEY_F1 = 59;
public static final int KEY_F2 = 60;
public static final int KEY_F3 = 61;
public static final int KEY_F4 = 62;
public static final int KEY_F5 = 63;
public static final int KEY_F6 = 64;
public static final int KEY_F7 = 65;
public static final int KEY_F8 = 66;
public static final int KEY_F9 = 67;
public static final int KEY_F10 = 68;
public static final int KEY_NUMLOCK = 69;
public static final int KEY_SCROLLLOCK = 70;
public static final int KEY_KP7 = 71;
public static final int KEY_KP8 = 72;
public static final int KEY_KP9 = 73;
public static final int KEY_KPMINUS = 74;
public static final int KEY_KP4 = 75;
public static final int KEY_KP5 = 76;
public static final int KEY_KP6 = 77;
public static final int KEY_KPPLUS = 78;
public static final int KEY_KP1 = 79;
public static final int KEY_KP2 = 80;
public static final int KEY_KP3 = 81;
public static final int KEY_KP0 = 82;
public static final int KEY_KPDOT = 83;
public static final int KEY_F11 = 87;
public static final int KEY_F12 = 88;
public static final int KEY_KPENTER = 96;
public static final int KEY_RIGHTCTRL = 97;
public static final int KEY_KPSLASH = 98;
public static final int KEY_SYSRQ = 99;
public static final int KEY_RIGHTALT = 100;
public static final int KEY_HOME = 102;
public static final int KEY_UP = 103;
public static final int KEY_PAGEUP = 104;
public static final int KEY_LEFT = 105;
public static final int KEY_RIGHT = 106;
public static final int KEY_END = 107;
public static final int KEY_DOWN = 108;
public static final int KEY_PAGEDOWN = 109;
public static final int KEY_INSERT = 110;
public static final int KEY_DELETE = 111;
public static final int KEY_KPEQUAL = 117;
public static final int KEY_PAUSE = 119;
public static final int KEY_KPCOMMA = 121;
public static final int KEY_LEFTMATA = 125;
public static final int KEY_RIGHTMETA = 126;
public static final int KEY_F13 = 183;
public static final int KEY_F14 = 184;
public static final int KEY_F15 = 185;
public static final int KEY_F16 = 186;
public static final int KEY_F17 = 187;
public static final int KEY_F18 = 188;
public static final int KEY_F19 = 189;
public static final int KEY_F20 = 190;
public static final int KEY_F21 = 191;
public static final int KEY_F22 = 192;
public static final int KEY_F23 = 193;
public static final int KEY_F24 = 194;
public static final int KEY_UNKNOWN = 240;
}

View File

@ -84,12 +84,16 @@ public class FCLBridge {
// Loader function
public void exit(int code) {
callback.onExit(code);
if (callback != null) {
callback.onExit(code);
}
}
// FCLBridge callbacks
public void setCursorMode(int mode) {
callback.onCursorModeChange(mode);
if (callback != null) {
callback.onCursorModeChange(mode);
}
}
public void setPrimaryClipString(String string) {