Skip to content

Commit 57dc058

Browse files
committed
Update wrapper, changes to arguments, presets update
1 parent 93729c7 commit 57dc058

15 files changed

Lines changed: 1874 additions & 1638 deletions

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package lbq.jsongen;
2+
3+
import static lbq.jsongen.JSONUtil.*;
4+
5+
import java.io.BufferedWriter;
6+
import java.io.IOException;
7+
import java.nio.file.Files;
8+
import java.nio.file.Path;
9+
import java.nio.file.Paths;
10+
11+
import org.json.JSONArray;
12+
import org.json.JSONObject;
13+
14+
public class GenArtifact {
15+
public static void main(String[] args) throws IOException {
16+
String prefab_name = "preset_launchwrapper";
17+
JSONObject json = JSONUtil.parseJSON(Paths.get("src/main/resources/" + prefab_name + "_prefab.json"));
18+
Path out = Paths.get("src/main/resources/" + prefab_name + ".json");
19+
JSONArray libraries = json.getJSONArray("libraries");
20+
JSONArray newLibraries = new JSONArray();
21+
for(Object o : libraries) {
22+
JSONObject lib = (JSONObject)o;
23+
JSONObject downloads = new JSONObject();
24+
JSONObject classifiersNew = null;
25+
JSONObject classifiers = null;
26+
String urlBase = lib.optString("url", null);
27+
String name = lib.getString("name");
28+
String url = urlBase == null ? null : getArtifactURL(urlBase, name, null);
29+
if(lib.has("downloads")) {
30+
JSONObject downloadsLib = lib.getJSONObject("downloads");
31+
if(downloadsLib.has("artifact")) {
32+
url = downloadsLib.getJSONObject("artifact").optString("url", url);
33+
}
34+
if(downloadsLib.has("classifiers")) {
35+
classifiers = downloadsLib.getJSONObject("classifiers");
36+
}
37+
}
38+
if(url != null) {
39+
JSONObject artifact = getArtifact(url, getArtifactPath(name, null), true);
40+
downloads.put("artifact", artifact);
41+
}
42+
if(classifiers != null) {
43+
classifiersNew = new JSONObject();
44+
for(String key : classifiers.keySet()) {
45+
JSONObject classifierArtifact = classifiers.getJSONObject(key);
46+
url = classifierArtifact.optString("url", getArtifactURL(urlBase, name, key));
47+
classifiersNew.put(key, getArtifact(url, getArtifactPath(name, key), true));
48+
}
49+
downloads.put("classifiers", classifiersNew);
50+
}
51+
lib.put("downloads", downloads);
52+
newLibraries.put(lib);
53+
}
54+
json.put("libraries", newLibraries);
55+
try (BufferedWriter writer = Files.newBufferedWriter(out)) {
56+
json.write(writer);
57+
}
58+
}
59+
}

src/main/java/lbq/jsongen/Generator.java

Lines changed: 136 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public Generator(Path dir, boolean update, boolean packToFolders, boolean genMan
4848
}
4949

5050
public void generate() throws IOException {
51+
Set<String> assets = new HashSet<>();
52+
Files.createDirectories(basePath.resolve("assets"));
5153
if (update) {
5254
Files.createDirectories(basePath);
5355
for (Path p : collectJSONs(basePath)) {
@@ -56,13 +58,56 @@ public void generate() throws IOException {
5658
if (version != null && !version.equals(id)) {
5759
continue;
5860
}
59-
boolean updated = update(jobj, postfix, lwjglCompat, micromixin, startTime);
61+
String assetHash = null;
62+
int assetSize = 0;
63+
64+
JSONObject assetIndex = jobj.optJSONObject("assetIndex");
65+
if(assetIndex != null) {
66+
String assetsId = assetIndex.getString("id");
67+
if(!assets.contains(assetsId)) {
68+
assets.add(assetsId);
69+
String url = assetIndex.getString("url");
70+
if(!url.contains("mojang.com")) {
71+
JSONObject assetsJson = JSONUtil.parseJSON(openStream(url));
72+
JSONObject objects = assetsJson.getJSONObject("objects");
73+
JSONObject custom = new JSONObject();
74+
Set<String> removeAssets = new HashSet<>();
75+
for(String s : objects.keySet()) {
76+
if(s.equals("index.xml")) {
77+
continue;
78+
}
79+
JSONObject obj = objects.getJSONObject(s);
80+
if(obj.has("url")) {
81+
removeAssets.add(s);
82+
if(custom.isEmpty()) {
83+
assetsJson.put("custom", custom);
84+
}
85+
custom.put(s, obj);
86+
}
87+
}
88+
objects.remove("index.xml");
89+
for(String s : removeAssets) {
90+
objects.remove(s);
91+
}
92+
writeJSON(assetsJson, basePath.resolve("assets/" + assetsId + ".json"));
93+
}
94+
}
95+
try {
96+
assetHash = Util.getSHA1(Files.newInputStream(basePath.resolve("assets/" + assetsId + ".json")));
97+
assetSize = Util.readAllBytes(Files.newInputStream(basePath.resolve("assets/" + assetsId + ".json"))).length;
98+
}
99+
catch (IOException e) {
100+
101+
}
102+
}
103+
boolean updated = update(jobj, postfix, lwjglCompat, micromixin, assetHash, assetSize, startTime);
60104
if (updated)
61105
System.out.println("Modified version: " + id);
62106
else {
63107
// System.out.println("Unmodified version: " + id);
64108
}
65109
id = jobj.getString("id");
110+
66111
if (updated) {
67112
writeJSON(jobj, basePath.resolve(id + ".json"));
68113
}
@@ -83,7 +128,7 @@ public void generate() throws IOException {
83128
}
84129
}
85130

86-
public static boolean update(JSONObject json, String postfix, boolean lwjglCompat, boolean micromixin,
131+
public static boolean update(JSONObject json, String postfix, boolean lwjglCompat, boolean micromixin, String assetsHash, int size,
87132
Instant startTime) throws IOException {
88133
boolean updated = false;
89134
Instant time = getTime(json.getString("releaseTime"));
@@ -93,7 +138,19 @@ public static boolean update(JSONObject json, String postfix, boolean lwjglCompa
93138
idNew = id + postfix;
94139
updated = true;
95140
}
141+
JSONObject assetIndex = json.getJSONObject("assetIndex");
142+
String assetIndexUrl = assetIndex.getString("url");
143+
String assetIndexHash = assetIndex.getString("sha1");
144+
if(assetsHash != null) {
145+
if(!assetsHash.equals(assetIndexHash) || !assetIndexUrl.equals( "https://mcphackers.org/BetterJSONs/jsons/assets/" + assetIndex.getString("id") + ".json")) {
146+
assetIndex.put("sha1", assetsHash);
147+
assetIndex.put("size", size);
148+
assetIndex.put("url", "https://mcphackers.org/BetterJSONs/jsons/assets/" + assetIndex.getString("id") + ".json");
149+
updated = true;
150+
}
151+
}
96152
json.put("id", idNew);
153+
lwjglCompat = id.endsWith("-lwjgl3");
97154
JSONArray verLibs = json.getJSONArray("libraries");
98155
if (time.compareTo(PAULSCODE_TIME) > 0) {
99156
JSONObject preset_paulscode = getPreset("paulscode");
@@ -102,15 +159,18 @@ public static boolean update(JSONObject json, String postfix, boolean lwjglCompa
102159
if (time.compareTo(LWJGL2_TIME) > 0) {
103160
JSONObject preset_lwjgl3 = getPreset("lwjgl3");
104161
updated |= mergePreset(preset_lwjgl3, json);
162+
if(lwjglCompat) {
163+
return false;
164+
}
105165
} else {
106166
if (lwjglCompat) {
107-
JSONObject preset_lwjgl3 = getPreset("lwjgl3");
108167
JSONObject preset_lwjgl3compat = getPreset("lwjgl3compat");
168+
JSONObject preset_lwjgl3 = getPreset("lwjgl3");
109169
updated |= removeLibrary(verLibs, "org.lwjgl.lwjgl", "lwjgl");
110170
updated |= removeLibrary(verLibs, "org.lwjgl.lwjgl", "lwjgl_util");
111171
updated |= removeLibrary(verLibs, "org.lwjgl.lwjgl", "lwjgl-platform");
112-
updated |= mergePreset(preset_lwjgl3, json);
113172
updated |= mergePreset(preset_lwjgl3compat, json);
173+
updated |= mergePreset(preset_lwjgl3, json);
114174
} else {
115175
JSONObject preset_lwjgl2 = getPreset("lwjgl2");
116176
updated |= mergePreset(preset_lwjgl2, json);
@@ -133,10 +193,16 @@ public static boolean update(JSONObject json, String postfix, boolean lwjglCompa
133193
}
134194
// TODO update LW base json to use arguments array instead (NOTE: MMC doesn't
135195
// support it)
136-
if (json.has("arguments")) {
137-
json.remove("arguments");
138-
updated = true;
139-
}
196+
// if (json.has("arguments")) {
197+
// json.remove("arguments");
198+
// updated = true;
199+
// }
200+
JSONObject arguments = new JSONObject();
201+
JSONArray argumentsGame = new JSONArray();
202+
JSONArray argumentsJvm = new JSONArray();
203+
arguments.put("game", argumentsGame);
204+
arguments.put("jvm", argumentsJvm);
205+
140206
JSONObject preset_launchwrapper = getPreset("launchwrapper");
141207
String minecraftArguments = preset_launchwrapper.getString("minecraftArguments");
142208
List<String> argsList = new ArrayList<>();
@@ -146,9 +212,69 @@ public static boolean update(JSONObject json, String postfix, boolean lwjglCompa
146212
if (skin != null) {
147213
argsList.add("--skinProxy");
148214
argsList.add(skin);
149-
preset_launchwrapper.put("minecraftArguments", String.join(" ", argsList));
215+
// preset_launchwrapper.put("minecraftArguments", String.join(" ", argsList));
150216
}
151217
}
218+
for(String s :argsList) {
219+
argumentsGame.put(s);
220+
}
221+
JSONObject a = new JSONObject();
222+
JSONObject features = new JSONObject();
223+
JSONArray rules = new JSONArray();
224+
JSONObject rule = new JSONObject();
225+
a.put("rules", rules);
226+
a.put("value", "--demo");
227+
rule.put("action", "allow");
228+
features.put("is_demo_user", true);
229+
rule.put("features", features);
230+
rules.put(rule);
231+
argumentsGame.put(a);
232+
233+
a = new JSONObject();
234+
features = new JSONObject();
235+
rules = new JSONArray();
236+
rule = new JSONObject();
237+
a.put("rules", rules);
238+
a.put("value", getStringsAsArray("--width", "${resolution_width}", "--height", "${resolution_height}"));
239+
rule.put("action", "allow");
240+
features.put("has_custom_resolution", true);
241+
rule.put("features", features);
242+
rules.put(rule);
243+
argumentsGame.put(a);
244+
245+
a = new JSONObject();
246+
features = new JSONObject();
247+
rules = new JSONArray();
248+
rule = new JSONObject();
249+
a.put("rules", rules);
250+
a.put("value", "--fullscreen");
251+
rule.put("action", "allow");
252+
features.put("has_fullscreen", true);
253+
rule.put("features", features);
254+
rules.put(rule);
255+
argumentsGame.put(a);
256+
257+
if(containsLibrary(verLibs, "org.lwjgl", "lwjgl")) {
258+
a = new JSONObject();
259+
JSONObject os = new JSONObject();
260+
rules = new JSONArray();
261+
rule = new JSONObject();
262+
a.put("rules", rules);
263+
a.put("value", getStringsAsArray("-XstartOnFirstThread", "-Djava.awt.headless=true"));
264+
rule.put("action", "allow");
265+
os.put("name", "osx");
266+
rule.put("os", os);
267+
rules.put(rule);
268+
argumentsJvm.put(a);
269+
}
270+
argumentsJvm.put("-Djava.library.path=${natives_directory}");
271+
argumentsJvm.put("-Dminecraft.launcher.brand=${launcher_name}");
272+
argumentsJvm.put("-Dminecraft.launcher.version=${launcher_version}");
273+
argumentsJvm.put("-cp");
274+
argumentsJvm.put("${classpath}");
275+
276+
preset_launchwrapper.put("arguments", arguments);
277+
preset_launchwrapper.remove("minecraftArguments");
152278
updated |= mergePreset(preset_launchwrapper, json);
153279
if (micromixin) {
154280
JSONObject preset_launchwrapper_micromixin = getPreset("launchwrapper_micromixin");
@@ -196,7 +322,7 @@ public void generateJSONs() throws IOException {
196322
System.out.println("skipped");
197323
continue;
198324
}
199-
update(versionJ, postfix, lwjglCompat, micromixin, startTime);
325+
update(versionJ, postfix, lwjglCompat, micromixin, null, 0, startTime);
200326
System.out.println("done");
201327
writeJSON(versionJ, jsonOut);
202328
if (packToFolders) {

0 commit comments

Comments
 (0)