Skip to content

Commit

Permalink
Use ProjectXBootstrap#loadConnectionSettings instead of `GameSettin…
Browse files Browse the repository at this point in the history
…gs#loadConnectionSettings`
  • Loading branch information
yihleego committed Feb 8, 2023
1 parent 627a17c commit c8f89ad
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 16 deletions.
62 changes: 48 additions & 14 deletions src/main/java/com/lucasallegri/bootstrap/ProjectXBootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
import javax.swing.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.zip.ZipFile;
Expand All @@ -33,6 +35,7 @@ public class ProjectXBootstrap {
private static final String MANIFEST_PATH = "META-INF/MANIFEST.MF";
private static final String MAIN_CLASS_KEY = "Main-Class:";
private static final String NAME_KEY = "Name:";
private static final Properties configs = new Properties();

public static void main(String[] args) throws Exception {
System.setProperty("com.threerings.io.enumPolicy", "ORDINAL");
Expand All @@ -43,6 +46,10 @@ public static void main(String[] args) throws Exception {
// X.dM("projectx.log");
invokeMethod("com.threerings.util.X", "dM", null, new Object[]{"projectx.log"});

loadConfigs();

loadConnectionSettings();

loadJarMods();

String ticket = null;
Expand Down Expand Up @@ -70,10 +77,49 @@ public static void main(String[] args) throws Exception {
invokeMethod("com.threerings.projectx.client.ProjectXApp", "startup", app, new Object[0]);
}

static void loadConfigs() throws Exception {
InputStream is = Files.newInputStream(Paths.get(USER_DIR + File.separator + "KnightLauncher.properties"));
configs.load(is);
is.close();
}

static void loadConnectionSettings() throws Exception {
// com.threerings.projectx.util.DeploymentConfig
Field configField = Class.forName("com.threerings.projectx.util.a").getDeclaredField("akf");
configField.setAccessible(true);
Object config = configField.get(null);
// com.samskivert.util.Config
Field propsField = Class.forName("com.samskivert.util.m").getDeclaredField("AQ");
propsField.setAccessible(true);
// deployment.properties
Properties properties = (Properties) propsField.get(config);
// Replace connection settings
Map<String, String> mapping = new HashMap<>();
mapping.put("server_host", "game.endpoint");
mapping.put("server_ports", "game.port");
mapping.put("datagram_ports", "game.port");
mapping.put("key.public", "game.publicKey");
mapping.put("client_root_url", "game.getdownURL");
for (Map.Entry<String, String> e : mapping.entrySet()) {
String newConf = configs.getProperty(e.getValue());
if (newConf == null) {
continue;
}
newConf = newConf.trim();
String oldConf = properties.getProperty(e.getKey());
if (newConf.length() > 0 && !newConf.equals(oldConf)) {
properties.setProperty(e.getKey(), newConf);
System.out.println("[deployment.properties] Replace [" + e.getKey() + "] '" + oldConf + "' -> '" + newConf + "'");
} else {
System.out.println("[deployment.properties] No change [" + e.getKey() + "] '" + oldConf + "'");
}
}
}

static void loadJarMods() {
// Read disabled jar mods from KnightLauncher.properties
Set<String> disabledJarMods = new HashSet<>();
String disabledJarModsString = getConfigValue("modloader.disabledMods");
String disabledJarModsString = configs.getProperty("modloader.disabledMods");
if (disabledJarModsString != null && disabledJarModsString.length() > 0) {
for (String disabledJarMod : disabledJarModsString.split(",")) {
disabledJarMod = disabledJarMod.trim();
Expand Down Expand Up @@ -184,18 +230,6 @@ static String readZip(File file, String entry) {
}
}

static String getConfigValue(String key) {
Properties _prop = new Properties();
String value;
try (InputStream is = Files.newInputStream(Paths.get(System.getProperty("user.dir") + File.separator + "KnightLauncher.properties"))) {
_prop.load(is);
value = _prop.getProperty(key);
return value;
} catch (IOException ignored) {
}
return null;
}

static Object invokeMethod(String className, String methodName, Object object, Object[] args) throws Exception {
Class<?> clazz = Class.forName(className);
Method[] methods = clazz.getDeclaredMethods();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,18 @@ public static void load() {
writer.println(Settings.gameAdditionalArgs);
writer.close();

loadConnectionSettings();

ProgressBar.setBarValue(1);
ProgressBar.finishTask();
} catch (FileNotFoundException | UnsupportedEncodingException e) {
log.error(e);
}
}

/**
* @see com.lucasallegri.bootstrap.ProjectXBootstrap
* @deprecated No longer use the way of modifying files.
*/
@Deprecated
private static void loadConnectionSettings() {
try {
FileUtil.extractFileWithinJar("/config/deployment.properties", LauncherGlobals.USER_DIR + "\\deployment.properties");
Expand Down

0 comments on commit c8f89ad

Please sign in to comment.