2018-09-17 10:07:32 +03:00
|
|
|
package ru.gravit.launcher;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.nio.file.NoSuchFileException;
|
|
|
|
import java.security.spec.InvalidKeySpecException;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.UUID;
|
2018-09-25 17:06:13 +03:00
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
2018-09-17 10:07:32 +03:00
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
2018-09-25 16:21:08 +03:00
|
|
|
import ru.gravit.launcher.profiles.ClientProfile;
|
2018-09-22 17:22:39 +03:00
|
|
|
import ru.gravit.utils.Version;
|
2018-09-17 10:20:34 +03:00
|
|
|
import ru.gravit.utils.helper.IOHelper;
|
2018-10-12 13:04:17 +03:00
|
|
|
import ru.gravit.utils.helper.JVMHelper;
|
2018-09-17 10:20:34 +03:00
|
|
|
import ru.gravit.utils.helper.SecurityHelper;
|
2018-09-17 10:07:32 +03:00
|
|
|
import ru.gravit.launcher.modules.ModulesManagerInterface;
|
|
|
|
import ru.gravit.launcher.serialize.HInput;
|
|
|
|
|
|
|
|
public final class Launcher {
|
2018-09-22 17:22:39 +03:00
|
|
|
|
2018-09-25 17:06:13 +03:00
|
|
|
// Authlib constants
|
|
|
|
@LauncherAPI
|
|
|
|
public static final String SKIN_URL_PROPERTY = "skinURL";
|
|
|
|
@LauncherAPI
|
|
|
|
public static final String SKIN_DIGEST_PROPERTY = "skinDigest";
|
|
|
|
@LauncherAPI
|
|
|
|
public static final String CLOAK_URL_PROPERTY = "cloakURL";
|
|
|
|
@LauncherAPI
|
|
|
|
public static final String CLOAK_DIGEST_PROPERTY = "cloakDigest";
|
|
|
|
// Used to determine from clientside is launched from launcher
|
|
|
|
public static final AtomicBoolean LAUNCHED = new AtomicBoolean(false);
|
|
|
|
|
2018-09-22 17:22:39 +03:00
|
|
|
static int readBuildNumber() {
|
|
|
|
try {
|
|
|
|
return Integer.valueOf(IOHelper.request(IOHelper.getResourceURL("buildnumber")));
|
|
|
|
} catch (IOException ignored) {
|
|
|
|
return 0; // Maybe dev env?
|
|
|
|
}
|
|
|
|
}
|
2018-09-22 17:33:00 +03:00
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
private static final AtomicReference<LauncherConfig> CONFIG = new AtomicReference<>();
|
|
|
|
@LauncherAPI
|
|
|
|
public static ModulesManagerInterface modulesManager = null;
|
|
|
|
@LauncherAPI
|
|
|
|
public static final int PROTOCOL_MAGIC_LEGACY = 0x724724_00 + 24;
|
|
|
|
@LauncherAPI
|
|
|
|
public static final int PROTOCOL_MAGIC = 0xA205B064; // e = 2.718281828
|
|
|
|
|
|
|
|
// Constants
|
|
|
|
@LauncherAPI
|
|
|
|
public static final String RUNTIME_DIR = "runtime";
|
|
|
|
@LauncherAPI
|
|
|
|
public static final String CONFIG_FILE = "config.bin";
|
|
|
|
@LauncherAPI
|
2018-09-25 16:21:08 +03:00
|
|
|
public static ClientProfile profile;
|
|
|
|
@LauncherAPI
|
2018-09-17 10:07:32 +03:00
|
|
|
public static final String INIT_SCRIPT_FILE = "init.js";
|
2018-09-19 15:03:52 +03:00
|
|
|
@LauncherAPI
|
|
|
|
public static final String API_SCRIPT_FILE = "engine/api.js";
|
2018-10-26 18:29:26 +03:00
|
|
|
public static final String CONFIG_SCRIPT_FILE = "config.js";
|
2018-09-17 10:07:32 +03:00
|
|
|
|
|
|
|
private static final Pattern UUID_PATTERN = Pattern.compile("-", Pattern.LITERAL);
|
2018-09-22 17:22:39 +03:00
|
|
|
public static int MAJOR = 4;
|
|
|
|
public static int MINOR = 0;
|
2018-10-21 15:12:36 +03:00
|
|
|
public static int PATCH = 4;
|
2018-09-22 17:22:39 +03:00
|
|
|
public static int BUILD = readBuildNumber();
|
2018-10-21 15:12:36 +03:00
|
|
|
public static Version.Type RELEASE = Version.Type.DEV;
|
2018-09-17 10:07:32 +03:00
|
|
|
|
|
|
|
@LauncherAPI
|
|
|
|
public static LauncherConfig getConfig() {
|
|
|
|
LauncherConfig config = CONFIG.get();
|
|
|
|
if (config == null) {
|
|
|
|
try (HInput input = new HInput(IOHelper.newInput(IOHelper.getResourceURL(CONFIG_FILE)))) {
|
|
|
|
config = new LauncherConfig(input);
|
|
|
|
} catch (IOException | InvalidKeySpecException e) {
|
|
|
|
throw new SecurityException(e);
|
|
|
|
}
|
|
|
|
CONFIG.set(config);
|
|
|
|
}
|
|
|
|
return config;
|
|
|
|
}
|
2018-09-26 11:54:14 +03:00
|
|
|
@LauncherAPI
|
|
|
|
public static void setConfig(LauncherConfig cfg)
|
|
|
|
{
|
|
|
|
CONFIG.set(cfg);
|
|
|
|
}
|
2018-09-17 10:07:32 +03:00
|
|
|
|
|
|
|
@LauncherAPI
|
|
|
|
public static URL getResourceURL(String name) throws IOException {
|
|
|
|
|
|
|
|
// Resolve URL and verify digest
|
|
|
|
URL url = IOHelper.getResourceURL(RUNTIME_DIR + '/' + name);
|
|
|
|
|
|
|
|
// Return verified URL
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
@LauncherAPI
|
|
|
|
public static String toHash(UUID uuid) {
|
|
|
|
return UUID_PATTERN.matcher(uuid.toString()).replaceAll("");
|
|
|
|
}
|
|
|
|
|
2018-09-22 17:22:39 +03:00
|
|
|
public static Version getVersion() {
|
2018-09-22 17:33:00 +03:00
|
|
|
return new Version(MAJOR, MINOR, PATCH, BUILD, RELEASE);
|
2018-09-22 17:22:39 +03:00
|
|
|
}
|
2018-10-12 13:04:17 +03:00
|
|
|
|
|
|
|
public static final boolean useAvanguard = true;
|
|
|
|
|
|
|
|
public static boolean isUsingAvanguard() {
|
|
|
|
return JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE && useAvanguard;
|
|
|
|
}
|
2018-09-17 10:07:32 +03:00
|
|
|
}
|