Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.13+ update #270

Closed
wants to merge 10 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import com.skcraft.launcher.model.loader.InstallProfile;
import com.skcraft.launcher.model.minecraft.Library;
import com.skcraft.launcher.model.minecraft.VersionManifest;
import com.skcraft.launcher.model.modpack.LauncherJSON;
import com.skcraft.launcher.model.modpack.Manifest;
import com.skcraft.launcher.model.modpack.ModpackVersion;
import com.skcraft.launcher.util.Environment;
import com.skcraft.launcher.util.HttpRequest;
import com.skcraft.launcher.util.SimpleLogFormatter;
Expand Down Expand Up @@ -215,7 +217,6 @@ private void processLoader(LinkedHashSet<Library> loaderLibraries, File file, Fi
public void downloadLibraries(File librariesDir) throws IOException, InterruptedException {
logSection("Downloading libraries...");

// TODO: Download libraries for different environments -- As of writing, this is not an issue
Environment env = Environment.getInstance();

for (Library library : loaderLibraries) {
Expand All @@ -242,6 +243,7 @@ public void downloadLibraries(File librariesDir) throws IOException, Interrupted
pathname = compressor.transformPathname(pathname);
}

// URL url = new URL(library.getDownloadUrl(env));
URL url = new URL(baseUrl + pathname);
File tempFile = File.createTempFile("launcherlib", null);

Expand Down Expand Up @@ -297,9 +299,7 @@ public void readVersionManifest(File path) throws IOException, InterruptedExcept

log.info("Loaded version manifest from " + path.getAbsolutePath());
} else {
URL url = url(String.format(
properties.getProperty("versionManifestUrl"),
manifest.getGameVersion()));
URL url = Launcher.getMetaURL(manifest.getGameVersion());

log.info("Fetching version manifest from " + url + "...");

Expand All @@ -311,7 +311,6 @@ public void readVersionManifest(File path) throws IOException, InterruptedExcept
.asJson(VersionManifest.class));
}
}

public void writeManifest(@NonNull File path) throws IOException {
logSection("Writing manifest...");

Expand Down
33 changes: 33 additions & 0 deletions launcher/src/main/java/com/skcraft/launcher/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import com.skcraft.launcher.auth.YggdrasilLoginService;
import com.skcraft.launcher.launch.LaunchSupervisor;
import com.skcraft.launcher.model.minecraft.VersionManifest;
import com.skcraft.launcher.model.modpack.LauncherJSON;
import com.skcraft.launcher.model.modpack.ModJSON;
import com.skcraft.launcher.model.modpack.ModpackVersion;
import com.skcraft.launcher.persistence.Persistence;
import com.skcraft.launcher.swing.SwingHelper;
import com.skcraft.launcher.update.UpdateManager;
Expand Down Expand Up @@ -366,6 +369,36 @@ public URL propUrl(String key, String... args) {
return HttpRequest.url(prop(key, args));
}

public static URL getMetaURL(String version) throws IOException, InterruptedException {
URL url = new URL("https://launchermeta.mojang.com/mc/game/version_manifest.json");
LauncherJSON launcherJSON = HttpRequest
.get(url)
.execute()
.expectResponseCode(200)
.returnContent()
.asJson(LauncherJSON.class);
for(ModpackVersion mpVersion : launcherJSON.getVersions()) {
if(mpVersion.getID().equalsIgnoreCase(version)) {
return new URL(mpVersion.getURL());
}
}
return null;
}

public static String getDownloadURL(String version) throws IOException, InterruptedException {
URL url = getMetaURL(version);
if(url == null) {
return "";
}
ModJSON modJson = HttpRequest
.get(url)
.execute()
.expectResponseCode(200)
.returnContent()
.asJson(ModJSON.class);
return modJson.getDownloads().getClient().getUrl();
}

/**
* Show the launcher.
*/
Expand Down
10 changes: 9 additions & 1 deletion launcher/src/main/java/com/skcraft/launcher/launch/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ private void addPlatformArgs() {
if (getEnvironment().getPlatform() == Platform.WINDOWS) {
builder.getFlags().add("-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump");
}

if(getEnvironment().getArch()=="x86"){
builder.getFlags().add("-Xss1M");
}
builder.getFlags().add("-Dminecraft.launcher.brand="+launcher.getProperties().getProperty("agentName"));
builder.getFlags().add("-Dminecraft.launcher.version="+launcher.getVersion());
}

/**
Expand Down Expand Up @@ -271,7 +277,8 @@ private void addJvmArgs() throws IOException {
private void addJarArgs() throws JsonProcessingException {
List<String> args = builder.getArgs();

String[] rawArgs = versionManifest.getMinecraftArguments().split(" +");
// String[] rawArgs = versionManifest.getMinecraftArguments().split(" +");
String[] rawArgs = versionManifest.getNewMinecraftArguments().split(" +");
StrSubstitutor substitutor = new StrSubstitutor(getCommandSubstitutions());
for (String arg : rawArgs) {
args.add(substitutor.replace(arg));
Expand Down Expand Up @@ -358,6 +365,7 @@ private Map<String, String> getCommandSubstitutions() throws JsonProcessingExcep
Map<String, String> map = new HashMap<String, String>();

map.put("version_name", versionManifest.getId());
map.put("version_type", versionManifest.getType());

map.put("auth_access_token", session.getAccessToken());
map.put("auth_session", session.getSessionToken());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.skcraft.launcher.model.minecraft;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;

import java.util.List;

/**
* @author barpec12
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class Arguments {

private List<Object> game;
barpec12 marked this conversation as resolved.
Show resolved Hide resolved
private List<Object> jvm;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.skcraft.launcher.model.minecraft;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;

/**
* @author barpec12
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class Artifact {

private String path;
private String url;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.skcraft.launcher.model.minecraft;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;

import java.util.HashMap;

/**
* @author barpec12
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class Downloads {

private Artifact artifact;
private HashMap<String, Artifact> classifiers;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@
import com.skcraft.launcher.util.Platform;
import lombok.Data;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class Library {

private String name;
private String path;
private transient String group;
private transient String artifact;
private transient String version;
@JsonProperty("url")
private String baseUrl;
private Map<String, String> natives;
private Downloads downloads;
private HashMap<String, String> natives;
private Extract extract;
private List<Rule> rules;

Expand Down Expand Up @@ -83,15 +85,15 @@ public String getVersion() {
return version;
}

public String getNativeString(Platform platform) {
public String getNativeString(Environment env) {
if (getNatives() != null) {
switch (platform) {
switch (env.getPlatform()) {
case LINUX:
return getNatives().get("linux");
return getNatives().get("linux") == null ? null : getNatives().get("linux").replace("${arch}", env.getArchBits());
case WINDOWS:
return getNatives().get("windows");
return getNatives().get("windows") == null ? null : getNatives().get("windows").replace("${arch}", env.getArchBits());
case MAC_OS_X:
return getNatives().get("osx");
return getNatives().get("osx") == null ? null : getNatives().get("osx").replace("${arch}", env.getArchBits());
default:
return null;
}
Expand All @@ -101,7 +103,7 @@ public String getNativeString(Platform platform) {
}

public String getFilename(Environment environment) {
String nativeString = getNativeString(environment.getPlatform());
String nativeString = getNativeString(environment);
if (nativeString != null) {
return String.format("%s-%s-%s.jar",
getArtifact(), getVersion(), nativeString);
Expand All @@ -111,6 +113,18 @@ public String getFilename(Environment environment) {
}

public String getPath(Environment environment) {
if(path!=null)
return path;
if(downloads!=null) {
String nativeString = getNativeString(environment);
if (nativeString != null) {
path = downloads.getClassifiers().get(nativeString).getPath();
return path;
} else {
path = downloads.getArtifact().getPath();
return path;
}
}
StringBuilder builder = new StringBuilder();
builder.append(getGroup().replace('.', '/'));
builder.append("/");
Expand All @@ -123,7 +137,6 @@ public String getPath(Environment environment) {
path = path.replace("${arch}", environment.getArchBits());
return path;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand All @@ -133,13 +146,16 @@ public boolean equals(Object o) {

if (name != null ? !name.equals(library.name) : library.name != null)
return false;

Environment env = Environment.getInstance();
if(getNativeString(env)==library.getNativeString(env))
return false;
return true;
}

@Override
public int hashCode() {
return name != null ? name.hashCode() : 0;
String nativeString = getNativeString(Environment.getInstance());
return name != null ? (name+(nativeString != null ? nativeString : "")).hashCode() : 0;
}

@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import lombok.Data;

import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashSet;

@Data
Expand All @@ -24,13 +25,30 @@ public class VersionManifest {
private String type;
private String processArguments;
private String minecraftArguments;
private Arguments arguments;
private String mainClass;
private int minimumLauncherVersion;
private LinkedHashSet<Library> libraries;
private HashMap<String, String> assetIndex;

@JsonIgnore
public String getAssetsIndex() {
return getAssets() != null ? getAssets() : "legacy";
}
@JsonIgnore
public String getNewMinecraftArguments() {
return getMinecraftArguments() != null ? getMinecraftArguments() : getNewArguments();
}
@JsonIgnore
private String getNewArguments(){
String result = "";
if(getArguments()!=null)
for(Object obj:getArguments().getGame()){
if(obj instanceof String) {
result += ((String)obj + " ");
}
}
return result;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.skcraft.launcher.model.modpack;

import lombok.Data;

@Data
public class DownloadClient {

private String sha1;
private int size;
private String url;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.skcraft.launcher.model.modpack;

import lombok.Data;

@Data
public class DownloadServer {

private String sha1;
private int size;
private String url;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.skcraft.launcher.model.modpack;

import lombok.Data;

@Data
public class LatestVersions {

private String release;
private String snapshot;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.skcraft.launcher.model.modpack;


import lombok.Data;

import java.util.List;

@Data
public class LauncherJSON {

private LatestVersions latest;
private List<ModpackVersion> versions;

public List<ModpackVersion> getVersions() {
return versions;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.skcraft.launcher.model.modpack;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class LauncherMeta {

private DownloadClient client;
private DownloadServer server;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.skcraft.launcher.model.modpack;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class ModJSON {

private LauncherMeta downloads;

}
Loading