Skip to content

Commit

Permalink
Merge branch 'fix3540/multimc-patch-json' of https://github.com/burni…
Browse files Browse the repository at this point in the history
…ngtnt/HMCL into prs
  • Loading branch information
burningtnt committed Jan 29, 2025
2 parents 50c9237 + 8150267 commit bb538d6
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private Version getPatch(FabricInfo fabricInfo, String gameVersion, String loade
libraries.add(new Library(Artifact.fromDescriptor(fabricInfo.intermediary.maven), "https://maven.fabricmc.net/", null));
libraries.add(new Library(Artifact.fromDescriptor(fabricInfo.loader.maven), "https://maven.fabricmc.net/", null));

return new Version(LibraryAnalyzer.LibraryType.FABRIC.getPatchId(), loaderVersion, 30000, arguments, mainClass, libraries);
return new Version(LibraryAnalyzer.LibraryType.FABRIC.getPatchId(), loaderVersion, Version.PRIORITY_LOADER, arguments, mainClass, libraries);
}

public static class FabricInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public void execute() throws Exception {
dependencyManager.checkLibraryCompletionAsync(forgeVersion, true)));

setResult(forgeVersion
.setPriority(30000)
.setPriority(Version.PRIORITY_LOADER)
.setId(LibraryAnalyzer.LibraryType.FORGE.getPatchId())
.setVersion(selfVersion));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void execute() throws Exception {
}

setResult(installProfile.getVersionInfo()
.setPriority(30000)
.setPriority(Version.PRIORITY_LOADER)
.setId(LibraryAnalyzer.LibraryType.FORGE.getPatchId())
.setVersion(selfVersion));
dependencies.add(dependencyManager.checkLibraryCompletionAsync(installProfile.getVersionInfo(), true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public boolean isRelyingOnDependencies() {
@Override
public void execute() throws Exception {
Version patch = JsonUtils.fromNonNullJson(downloadTask.getResult(), Version.class)
.setId(MINECRAFT.getPatchId()).setVersion(remote.getGameVersion()).setJar(null).setPriority(0);
.setId(MINECRAFT.getPatchId()).setVersion(remote.getGameVersion()).setJar(null).setPriority(Version.PRIORITY_MC);
setResult(patch);

Version version = new Version(this.version.getId()).addPatch(patch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ public void execute() throws Exception {
dependencyManager.checkLibraryCompletionAsync(neoForgeVersion, true)));

setResult(neoForgeVersion
.setPriority(30000)
.setPriority(Version.PRIORITY_LOADER)
.setId(LibraryAnalyzer.LibraryType.NEO_FORGE.getPatchId())
.setVersion(selfVersion));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private Version getPatch(QuiltInfo quiltInfo, String gameVersion, String loaderV
libraries.add(new Library(Artifact.fromDescriptor(quiltInfo.intermediary.maven), getMavenRepositoryByGroup(quiltInfo.intermediary.maven), null));
libraries.add(new Library(Artifact.fromDescriptor(quiltInfo.loader.maven), getMavenRepositoryByGroup(quiltInfo.loader.maven), null));

return new Version(LibraryAnalyzer.LibraryType.QUILT.getPatchId(), loaderVersion, 30000, arguments, mainClass, libraries);
return new Version(LibraryAnalyzer.LibraryType.QUILT.getPatchId(), loaderVersion, Version.PRIORITY_LOADER, arguments, mainClass, libraries);
}

private static String getMavenRepositoryByGroup(String maven) {
Expand Down
4 changes: 4 additions & 0 deletions HMCLCore/src/main/java/org/jackhuang/hmcl/game/Arguments.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public Arguments addJVMArguments(List<String> jvmArguments) {
return new Arguments(getGame(), Lang.merge(getJvm(), list));
}

public Arguments addJVMArgumentsDirect(List<Argument> list) {
return new Arguments(getGame(), Lang.merge(getJvm(), list));
}

public static Arguments merge(Arguments a, Arguments b) {
if (a == null)
return b;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,15 @@ public File getLibrariesDirectory(Version version) {

@Override
public File getLibraryFile(Version version, Library lib) {
if ("local".equals(lib.getHint()) && lib.getFileName() != null)
return new File(getVersionRoot(version.getId()), "libraries/" + lib.getFileName());
else
return new File(getLibrariesDirectory(version), lib.getPath());
if ("local".equals(lib.getHint())) {
if (lib.getFileName() != null) {
return new File(getVersionRoot(version.getId()), "libraries/" + lib.getFileName());
}

return new File(getVersionRoot(version.getId()), "libraries/" + lib.getArtifact().getFileName());
}

return new File(getLibrariesDirectory(version), lib.getPath());
}

public Path getArtifactFile(Version version, Artifact artifact) {
Expand Down
43 changes: 35 additions & 8 deletions HMCLCore/src/main/java/org/jackhuang/hmcl/game/Library.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
*/
package org.jackhuang.hmcl.game;

import com.google.gson.*;
import com.google.gson.JsonParseException;
import com.google.gson.annotations.SerializedName;
import org.jackhuang.hmcl.util.Constants;
import org.jackhuang.hmcl.util.Immutable;
import org.jackhuang.hmcl.util.ToStringBuilder;
import org.jackhuang.hmcl.util.gson.JsonUtils;
import org.jackhuang.hmcl.util.gson.TolerableValidationException;
import org.jackhuang.hmcl.util.gson.Validation;
import org.jackhuang.hmcl.util.platform.Architecture;
Expand All @@ -46,7 +47,7 @@ public class Library implements Comparable<Library>, Validation {
private final String url;
private final LibrariesDownloadInfo downloads;
private final ExtractRules extract;
private final Map<OperatingSystem, String> natives;
private final Map<String, String> natives;
private final List<CompatibilityRule> rules;
private final List<String> checksums;

Expand All @@ -64,7 +65,7 @@ public Library(Artifact artifact, String url, LibrariesDownloadInfo downloads) {
this(artifact, url, downloads, null, null, null, null, null, null);
}

public Library(Artifact artifact, String url, LibrariesDownloadInfo downloads, List<String> checksums, ExtractRules extract, Map<OperatingSystem, String> natives, List<CompatibilityRule> rules, String hint, String filename) {
public Library(Artifact artifact, String url, LibrariesDownloadInfo downloads, List<String> checksums, ExtractRules extract, Map<String, String> natives, List<CompatibilityRule> rules, String hint, String filename) {
this.artifact = artifact;
this.url = url;
this.downloads = downloads;
Expand Down Expand Up @@ -93,13 +94,33 @@ public String getVersion() {
}

public String getClassifier() {
if (artifact.getClassifier() == null)
if (natives != null && natives.containsKey(OperatingSystem.CURRENT_OS))
return natives.get(OperatingSystem.CURRENT_OS).replace("${arch}", Architecture.SYSTEM_ARCH.getBits().getBit());
else
if (artifact.getClassifier() == null) {
if (natives == null) {
return null;
else
}

String current = natives.get(OperatingSystem.CURRENT_OS.getCheckedName());
if (current == null) {
for (String value : natives.values()) {
int i = value.indexOf('-');
if (i == -1) {
continue;
}

Architecture architecture = JsonUtils.GSON.fromJson(value.substring(i + 1), Architecture.class);
if (architecture == Architecture.SYSTEM_ARCH) {
current = natives.get(value);
break;
}
}
}
if (current == null) {
return null;
}
return current.replace("${arch}", Architecture.SYSTEM_ARCH.getBits().getBit());
} else {
return artifact.getClassifier();
}
}

public ExtractRules getExtract() {
Expand All @@ -125,6 +146,10 @@ protected LibraryDownloadInfo getRawDownloadInfo() {
}
}

public Artifact getArtifact() {
return artifact;
}

public String getPath() {
LibraryDownloadInfo temp = getRawDownloadInfo();
if (temp != null && temp.getPath() != null)
Expand Down Expand Up @@ -159,6 +184,7 @@ public List<CompatibilityRule> getRules() {

/**
* Hint for how to locate the library file.
*
* @return null for default, "local" for location in version/&lt;version&gt;/libraries/filename
*/
@Nullable
Expand All @@ -168,6 +194,7 @@ public String getHint() {

/**
* Available when hint is "local"
*
* @return the filename of the local library in version/&lt;version&gt;/libraries/$filename
*/
@Nullable
Expand Down
9 changes: 9 additions & 0 deletions HMCLCore/src/main/java/org/jackhuang/hmcl/game/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
@Immutable
public class Version implements Comparable<Version>, Validation {

/**
* Patches with higher priority can override info from other patches, such as mainClass.
*/
public static final int PRIORITY_MC = 0, PRIORITY_LOADER = 30000;

private final String id;
private final String version;
private final Integer priority;
Expand Down Expand Up @@ -396,6 +401,10 @@ public Version setMinecraftArguments(String minecraftArguments) {
return new Version(resolved, id, version, priority, minecraftArguments, arguments, mainClass, inheritsFrom, jar, assetIndex, assets, complianceLevel, javaVersion, libraries, compatibilityRules, downloads, logging, type, time, releaseTime, minimumLauncherVersion, hidden, root, patches);
}

public Version setJavaVersion(GameJavaVersion javaVersion) {
return new Version(resolved, id, version, priority, minecraftArguments, arguments, mainClass, inheritsFrom, jar, assetIndex, assets, complianceLevel, javaVersion, libraries, compatibilityRules, downloads, logging, type, time, releaseTime, minimumLauncherVersion, hidden, root, patches);
}

public Version setArguments(Arguments arguments) {
return new Version(resolved, id, version, priority, minecraftArguments, arguments, mainClass, inheritsFrom, jar, assetIndex, assets, complianceLevel, javaVersion, libraries, compatibilityRules, downloads, logging, type, time, releaseTime, minimumLauncherVersion, hidden, root, patches);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
import org.jackhuang.hmcl.util.StringUtils;
import org.jackhuang.hmcl.util.platform.CommandBuilder;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -54,7 +51,12 @@ public Version build() {
// The official launcher will not parse the "arguments" property when it detects the presence of "mcArgs".
// The "arguments" property with the "rule" is simply ignored here.
this.mcArgs.addAll(this.game.stream().map(arg -> arg.toString(new HashMap<>(), new HashMap<>())).flatMap(Collection::stream).collect(Collectors.toList()));
ret = ret.setArguments(null);

// For compatibility with MultiMC launcher, we only ignore the game arguments but keep the presence of vm arguments.
Arguments arguments = ret.getArguments().orElse(null);
if (arguments != null) {
ret.setArguments(arguments.withGame(Collections.emptyList()));
}

// Since $ will be escaped in linux, and our maintain of minecraftArgument will not cause escaping,
// so we regenerate the minecraftArgument without escaping.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Immutable
public class TLauncherLibrary {
Expand Down Expand Up @@ -58,7 +59,9 @@ public Library toLibrary() {
new LibrariesDownloadInfo(artifact, classifiers),
checksums,
extract,
natives,
natives.entrySet().stream().collect(Collectors.toMap(
entry -> entry.getKey().getCheckedName(), Map.Entry::getValue
)),
rules,
null,
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,57 @@
import org.jackhuang.hmcl.game.Library;
import org.jackhuang.hmcl.util.Immutable;
import org.jackhuang.hmcl.util.Lang;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
*
* @author huangyuhui
*/
@Immutable
public final class MultiMCInstancePatch {

private final String name;
private final String version;
private final int order;

@SerializedName("mcVersion")
private final String gameVersion;
private final String mainClass;
private final String fileId;

@SerializedName("compatibleJavaMajors")
private final int[] javaMajors;

@SerializedName("+tweakers")
@Nullable
private final List<String> tweakers;

@SerializedName("+jvmArgs")
@Nullable
private final List<String> jvmArgs;

@SerializedName("+libraries")
@Nullable
private final List<Library> _libraries;

@SerializedName("libraries")
@Nullable
private final List<Library> libraries;

public MultiMCInstancePatch() {
this("", "", "", "", "", Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
}

public MultiMCInstancePatch(String name, String version, String gameVersion, String mainClass, String fileId, List<String> tweakers, List<Library> _libraries, List<Library> libraries) {
public MultiMCInstancePatch(String name, String version, int order, String gameVersion, String mainClass, String fileId, int[] javaMajors, @Nullable List<String> tweakers, @Nullable List<String> jvmArgs, @Nullable List<Library> _libraries, @Nullable List<Library> libraries) {
this.name = name;
this.version = version;
this.order = order;
this.gameVersion = gameVersion;
this.mainClass = mainClass;
this.fileId = fileId;
this.tweakers = new ArrayList<>(tweakers);
this._libraries = new ArrayList<>(_libraries);
this.libraries = new ArrayList<>(libraries);
this.javaMajors = javaMajors;
this.tweakers = tweakers;
this.jvmArgs = jvmArgs;
this._libraries = _libraries;
this.libraries = libraries;
}

public String getName() {
Expand All @@ -73,6 +82,14 @@ public String getVersion() {
return version;
}

public int getOrder() {
return order;
}

public int[] getJavaMajors() {
return javaMajors;
}

public String getGameVersion() {
return gameVersion;
}
Expand All @@ -86,11 +103,14 @@ public String getFileId() {
}

public List<String> getTweakers() {
return Collections.unmodifiableList(tweakers);
return tweakers != null ? Collections.unmodifiableList(tweakers) : Collections.emptyList();
}

public List<String> getJvmArgs() {
return jvmArgs != null ? Collections.unmodifiableList(jvmArgs) : Collections.emptyList();
}

public List<Library> getLibraries() {
return Lang.merge(_libraries, libraries);
}

}
Loading

0 comments on commit bb538d6

Please sign in to comment.