Launching 1.13
This commit is contained in:
1 parent
fabb6b50b4
commit
06b3ec8337
9 files changed
+137
-63
No files matched your search
@@ -47,7 +47,6 @@ import org.jackhuang.hmcl.ui.LogWindow;
|
||||
import org.jackhuang.hmcl.ui.MainFrame;
|
||||
import org.jackhuang.hmcl.util.CrashReporter;
|
||||
import org.jackhuang.hmcl.util.DefaultPlugin;
|
||||
import org.jackhuang.hmcl.util.MathUtils;
|
||||
import org.jackhuang.hmcl.util.ui.MessageBox;
|
||||
import org.jackhuang.hmcl.util.StrUtils;
|
||||
import org.jackhuang.hmcl.util.lang.SupportedLocales;
|
||||
|
||||
@@ -21,8 +21,11 @@ import org.jackhuang.hmcl.api.game.LaunchOptions;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import org.jackhuang.hmcl.util.StrUtils;
|
||||
import org.jackhuang.hmcl.api.HMCLog;
|
||||
import org.jackhuang.hmcl.util.sys.OS;
|
||||
@@ -30,18 +33,19 @@ import org.jackhuang.hmcl.core.GameException;
|
||||
import org.jackhuang.hmcl.api.auth.UserProfileProvider;
|
||||
import org.jackhuang.hmcl.core.version.MinecraftLibrary;
|
||||
import org.jackhuang.hmcl.core.service.IMinecraftService;
|
||||
import org.jackhuang.hmcl.core.version.LoggingInfo;
|
||||
import org.jackhuang.hmcl.core.version.Argument;
|
||||
import org.jackhuang.hmcl.core.version.Arguments;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class MinecraftLoader extends AbstractMinecraftLoader {
|
||||
|
||||
|
||||
public MinecraftLoader(LaunchOptions p, IMinecraftService provider, UserProfileProvider lr) throws GameException {
|
||||
super(p, provider, p.getLaunchVersion(), lr);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void makeSelf(List<String> res) throws GameException {
|
||||
StringBuilder library = new StringBuilder("");
|
||||
@@ -71,39 +75,40 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
|
||||
res.add(library.toString().substring(0, library.length() - File.pathSeparator.length()));
|
||||
res.add(version.mainClass);
|
||||
|
||||
if (version.minecraftArguments == null)
|
||||
throw new GameException(new NullPointerException("Minecraft Arguments can not be null."));
|
||||
String[] splitted = StrUtils.tokenize(version.minecraftArguments);
|
||||
|
||||
String game_assets = assetProvider.provide(version, !options.isNotCheckGame());
|
||||
|
||||
for (String t : splitted) {
|
||||
t = t.replace("${auth_player_name}", lr.getUserName());
|
||||
t = t.replace("${auth_session}", lr.getSession());
|
||||
t = t.replace("${auth_uuid}", lr.getUserId());
|
||||
t = t.replace("${version_name}", options.getVersionName());
|
||||
t = t.replace("${profile_name}", options.getName());
|
||||
t = t.replace("${version_type}", options.getType());
|
||||
t = t.replace("${game_directory}", service.version().getRunDirectory(version.id).getAbsolutePath());
|
||||
t = t.replace("${game_assets}", game_assets);
|
||||
t = t.replace("${assets_root}", service.asset().getAssets(version.getAssetsIndex().getId()).getAbsolutePath());
|
||||
t = t.replace("${auth_access_token}", lr.getAccessToken());
|
||||
t = t.replace("${user_type}", lr.getUserType());
|
||||
t = t.replace("${assets_index_name}", version.getAssetsIndex().getId());
|
||||
t = t.replace("${user_properties}", lr.getUserProperties());
|
||||
res.add(t);
|
||||
}
|
||||
|
||||
|
||||
Map<String, String> keys = new HashMap() {{
|
||||
put("${auth_player_name}", lr.getUserName());
|
||||
put("${auth_session}", lr.getSession());
|
||||
put("${auth_uuid}", lr.getUserId());
|
||||
put("${version_name}", options.getVersionName());
|
||||
put("${profile_name}", options.getName());
|
||||
put("${version_type}", options.getType());
|
||||
put("${game_directory}", service.version().getRunDirectory(version.id).getAbsolutePath());
|
||||
put("${game_assets}", game_assets);
|
||||
put("${assets_root}", service.asset().getAssets(version.getAssetsIndex().getId()).getAbsolutePath());
|
||||
put("${auth_access_token}", lr.getAccessToken());
|
||||
put("${user_type}", lr.getUserType());
|
||||
put("${assets_index_name}", version.getAssetsIndex().getId());
|
||||
put("${user_properties}", lr.getUserProperties());
|
||||
put("${is_demo_user}", false);
|
||||
}};
|
||||
|
||||
Map<String, Boolean> features = new HashMap<>();
|
||||
|
||||
res.addAll(Arguments.parseArguments(version.arguments.game, keys, features));
|
||||
res.addAll(Arguments.parseStringArguments(Arrays.asList(StrUtils.tokenize(version.minecraftArguments)), keys));
|
||||
|
||||
if (res.indexOf("--gameDir") != -1 && res.indexOf("--workDir") != -1) {
|
||||
res.add("--workDir");
|
||||
res.add(gameDir.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void appendJVMArgs(List<String> list) {
|
||||
super.appendJVMArgs(list);
|
||||
|
||||
|
||||
try {
|
||||
if (OS.os() == OS.OSX) {
|
||||
list.add("-Xdock:icon=" + service.asset().getAssetObject(version.getAssetsIndex().getId(), "icons/minecraft.icns").getAbsolutePath());
|
||||
@@ -114,7 +119,7 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
|
||||
}
|
||||
|
||||
list.add("-Dminecraft.client.jar=" + version.getJar(service.baseDirectory()).getAbsolutePath());
|
||||
|
||||
|
||||
/*
|
||||
if (version.logging != null && version.logging.containsKey("client")) {
|
||||
LoggingInfo logging = version.logging.get("client");
|
||||
@@ -122,15 +127,15 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
|
||||
if (file.exists())
|
||||
list.add(logging.argument.replace("${path}", file.getAbsolutePath()));
|
||||
}
|
||||
*/
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
private final IAssetProvider DEFAULT_ASSET_PROVIDER = (t, allow) -> {
|
||||
return new File(service.baseDirectory(), "assets").getAbsolutePath();
|
||||
};
|
||||
|
||||
|
||||
private IAssetProvider assetProvider = DEFAULT_ASSET_PROVIDER;
|
||||
|
||||
|
||||
public void setAssetProvider(IAssetProvider assetProvider) {
|
||||
if (assetProvider == null)
|
||||
this.assetProvider = DEFAULT_ASSET_PROVIDER;
|
||||
|
||||
@@ -54,16 +54,7 @@ public class MinecraftLibrary extends AbstractMinecraftLibrary {
|
||||
*/
|
||||
@Override
|
||||
public boolean allow() {
|
||||
if (rules != null) {
|
||||
boolean flag = false;
|
||||
for (Rules r : rules)
|
||||
if ("disallow".equals(r.action()))
|
||||
return false;
|
||||
else if ("allow".equals(r.action()))
|
||||
flag = true;
|
||||
return flag;
|
||||
} else
|
||||
return true;
|
||||
return Rules.allow(rules);
|
||||
}
|
||||
|
||||
private String formatArch(String nati) {
|
||||
|
||||
@@ -43,6 +43,8 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
|
||||
|
||||
@SerializedName("minecraftArguments")
|
||||
public String minecraftArguments;
|
||||
@SerializedName("arguments")
|
||||
public Arguments arguments;
|
||||
@SerializedName("mainClass")
|
||||
public String mainClass;
|
||||
@SerializedName("time")
|
||||
@@ -151,16 +153,16 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
|
||||
}
|
||||
parent = parent.resolve(provider, resolvedSoFar);
|
||||
MinecraftVersion result = new MinecraftVersion(
|
||||
this.minecraftArguments != null ? this.minecraftArguments : parent.minecraftArguments,
|
||||
this.mainClass != null ? this.mainClass : parent.mainClass,
|
||||
this.time, this.id, this.type, parent.processArguments, this.releaseTime,
|
||||
this.assets != null ? this.assets : parent.assets,
|
||||
this.jar != null ? this.jar : parent.jar,
|
||||
null, this.runDir, parent.minimumLauncherVersion,
|
||||
this.libraries != null ? ArrayUtils.merge(this.libraries, parent.libraries) : parent.libraries, this.hidden,
|
||||
this.downloads != null ? this.downloads : parent.downloads,
|
||||
this.assetIndex != null ? this.assetIndex : parent.assetIndex,
|
||||
this.logging != null ? this.logging : parent.logging);
|
||||
this.minecraftArguments != null ? this.minecraftArguments : parent.minecraftArguments,
|
||||
this.mainClass != null ? this.mainClass : parent.mainClass,
|
||||
this.time, this.id, this.type, parent.processArguments, this.releaseTime,
|
||||
this.assets != null ? this.assets : parent.assets,
|
||||
this.jar != null ? this.jar : parent.jar,
|
||||
null, this.runDir, parent.minimumLauncherVersion,
|
||||
this.libraries != null ? ArrayUtils.merge(this.libraries, parent.libraries) : parent.libraries, this.hidden,
|
||||
this.downloads != null ? this.downloads : parent.downloads,
|
||||
this.assetIndex != null ? this.assetIndex : parent.assetIndex,
|
||||
this.logging != null ? this.logging : parent.logging);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -203,7 +205,7 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
|
||||
return false;
|
||||
return Objects.equals(this.id, ((MinecraftVersion) obj).id);
|
||||
}
|
||||
|
||||
|
||||
public AssetIndexDownloadInfo getAssetsIndex() {
|
||||
if (assetIndex == null)
|
||||
assetIndex = new AssetIndexDownloadInfo(assets == null ? AssetsIndex.DEFAULT_ASSET_NAME : assets);
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
package org.jackhuang.hmcl.core.version;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import org.jackhuang.hmcl.util.StrUtils;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.jackhuang.hmcl.util.sys.OS;
|
||||
|
||||
/**
|
||||
@@ -31,6 +32,8 @@ public class OSRestriction {
|
||||
private String version;
|
||||
@SerializedName("name")
|
||||
public String name;
|
||||
@SerializedName("arch")
|
||||
public String arch;
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
@@ -49,6 +52,24 @@ public class OSRestriction {
|
||||
}
|
||||
|
||||
public boolean isCurrentOS() {
|
||||
return StrUtils.isBlank(getName()) || OS.os().name().equalsIgnoreCase(getName());
|
||||
if (name != null && !OS.os().name().equalsIgnoreCase(name))
|
||||
return false;
|
||||
if (version != null) {
|
||||
try {
|
||||
Pattern pattern = Pattern.compile(version);
|
||||
Matcher matcher = pattern.matcher(System.getProperty("os.version"));
|
||||
if (!matcher.matches())
|
||||
return false;
|
||||
} catch (Throwable t) {}
|
||||
}
|
||||
if (arch != null) {
|
||||
try {
|
||||
Pattern pattern = Pattern.compile(arch);
|
||||
Matcher matcher = pattern.matcher(System.getProperty("os.arch"));
|
||||
if (!matcher.matches())
|
||||
return false;
|
||||
} catch (Throwable t) {}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,10 @@
|
||||
package org.jackhuang.hmcl.core.version;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -29,12 +33,40 @@ public class Rules {
|
||||
private String action;
|
||||
@SerializedName("os")
|
||||
private OSRestriction os;
|
||||
@SerializedName("features")
|
||||
private Map<String, Boolean> features;
|
||||
|
||||
public Rules() {
|
||||
}
|
||||
|
||||
public String action() {
|
||||
return os == null || os.isCurrentOS() ? action : null;
|
||||
public String action(Map<String, Boolean> features) {
|
||||
if (os != null && !os.isCurrentOS()) return null;
|
||||
if (this.features != null) {
|
||||
for (Map.Entry<String, Boolean> entry : this.features.entrySet())
|
||||
if (!features.containsKey(entry.getKey()))
|
||||
return null;
|
||||
else
|
||||
if (!features.get(entry.getKey()).equals(entry.getValue()))
|
||||
return null;
|
||||
}
|
||||
return action;
|
||||
}
|
||||
|
||||
public static boolean allow(Collection<Rules> c) {
|
||||
return allow(c, Collections.EMPTY_MAP);
|
||||
}
|
||||
|
||||
public static boolean allow(Collection<Rules> c, Map<String, Boolean> features) {
|
||||
if (c != null) {
|
||||
boolean flag = false;
|
||||
for (Rules r : c)
|
||||
if ("disallow".equals(r.action(features)))
|
||||
return false;
|
||||
else if ("allow".equals(r.action(features)))
|
||||
flag = true;
|
||||
return flag;
|
||||
} else
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,6 +20,8 @@ package org.jackhuang.hmcl.util;
|
||||
import org.jackhuang.hmcl.util.lang.SupportedLocales;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import org.jackhuang.hmcl.core.version.Argument;
|
||||
import org.jackhuang.hmcl.core.version.RuledArgument;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -27,7 +29,10 @@ import com.google.gson.GsonBuilder;
|
||||
*/
|
||||
public final class C {
|
||||
|
||||
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||
public static final Gson GSON = new GsonBuilder()
|
||||
.registerTypeAdapter(RuledArgument.class, new RuledArgument.RuledArgumentSerializer())
|
||||
.registerTypeAdapter(Argument.class, new Argument.ArgumentSerializer())
|
||||
.setPrettyPrinting().create();
|
||||
|
||||
//http://repo1.maven.org/maven2
|
||||
public static final String URL_PUBLISH = "http://www.mcbbs.net/thread-142335-1-1.html";
|
||||
@@ -35,7 +40,7 @@ public final class C {
|
||||
|
||||
public static final String URL_FORGE_LIST = "http://files.minecraftforge.net/maven/net/minecraftforge/forge/json";
|
||||
public static final String URL_LITELOADER_LIST = "http://dl.liteloader.com/versions/versions.json";
|
||||
|
||||
|
||||
public static final String LINE_SEPARATOR = System.getProperty("line.separator");
|
||||
|
||||
private C() {
|
||||
|
||||
@@ -21,6 +21,8 @@ import org.jackhuang.hmcl.api.func.Predicate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import org.jackhuang.hmcl.api.func.Function;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -31,7 +33,7 @@ public final class CollectionUtils {
|
||||
private CollectionUtils() {
|
||||
}
|
||||
|
||||
public static <T> ArrayList<T> filter(Collection<T> coll, Predicate<T> p) {
|
||||
public static <T> List<T> filter(Collection<T> coll, Predicate<T> p) {
|
||||
ArrayList<T> newColl = new ArrayList<>();
|
||||
for (T t : coll)
|
||||
if (p.apply(t))
|
||||
@@ -39,6 +41,20 @@ public final class CollectionUtils {
|
||||
return newColl;
|
||||
}
|
||||
|
||||
public static <U, V> List<V> map(Collection<U> coll, Function<U, V> p) {
|
||||
ArrayList<V> newColl = new ArrayList<>(coll.size());
|
||||
for (U t : coll)
|
||||
newColl.add(p.apply(t));
|
||||
return newColl;
|
||||
}
|
||||
|
||||
public static <U, V> List<V> flatMap(Collection<U> coll, Function<U, Collection<V>> p) {
|
||||
ArrayList<V> newColl = new ArrayList<>(coll.size());
|
||||
for (U t : coll)
|
||||
newColl.addAll(p.apply(t));
|
||||
return newColl;
|
||||
}
|
||||
|
||||
public static <T> boolean removeIf(Collection<T> coll, Predicate<T> p) {
|
||||
boolean removed = false;
|
||||
final Iterator<T> each = coll.iterator();
|
||||
|
||||
@@ -154,8 +154,11 @@ public final class StrUtils {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String[] tokenize(String paramString1) {
|
||||
return tokenize(paramString1, " \t\n\r\f");
|
||||
public static String[] tokenize(String str) {
|
||||
if (str == null)
|
||||
return new String[0];
|
||||
else
|
||||
return tokenize(str, " \t\n\r\f");
|
||||
}
|
||||
|
||||
public static String[] tokenize(String str, String delim) {
|
||||
|
||||
Reference in new issue
Block a user