Skip to content

Commit e2dfcbd

Browse files
committed
deploy: 34a0a61
1 parent d4a2a46 commit e2dfcbd

13 files changed

Lines changed: 32 additions & 64 deletions
-1.56 KB
Binary file not shown.

ModFileLoader/src/main/java/com/redlimerl/mcsr/MCSRModLoader.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@
1717
public class MCSRModLoader {
1818

1919
public static final String VERSION = "v4";
20-
private static final Path MODPACKS_PATH = Paths.get("./modpacks/" + VERSION);
20+
private static final Path MODPACKS_PATH = Paths.get("modpacks/" + VERSION);
2121
public static final Gson GSON = new GsonBuilder().serializeNulls().disableHtmlEscaping().create();
22-
public static String GITHUB_TOKEN = "none";
2322

2423
public static void main(String[] args) throws Throwable {
25-
GITHUB_TOKEN = args[0];
2624
List<ModInfo> modInfoList = new ArrayList<>();
2725
FabricLoader fabricLoader = null;
2826

29-
mod: for (JsonElement jsonElement : HttpRequestHelper.getJsonFromUrl("https://raw.githubusercontent.com/tildejustin/mcsr-meta/schema-6/mods.json").getAsJsonObject().getAsJsonArray("mods")) {
27+
mod: for (JsonElement jsonElement : HttpRequestHelper.getJsonFromUrl("https://raw.githubusercontent.com/tildejustin/mcsr-meta/schema-7/mods.json").getAsJsonObject().getAsJsonArray("mods")) {
3028
ModInfo modInfo = GSON.fromJson(jsonElement, ModInfo.class);
3129
for (ModInfo.ModVersion version : modInfo.versions()) {
3230
for (String s : version.target_version()) {
@@ -66,12 +64,12 @@ public static void main(String[] args) throws Throwable {
6664
Set<String> osSet = Set.of("Windows", "OSX", "Linux");
6765

6866
for (String os : osSet) {
69-
Set<String> whitelist = Sets.newHashSet("antigone", "fast_reset", "krypton", "lazydfu", "lazystronghold", "lithium", "starlight", "voyager", "speedrunapi", "state-output");
67+
Set<String> whitelist = Sets.newHashSet("antigone", "antiresourcereload", "boundlesswindow", "fast_reset", "krypton", "lazydfu", "lazystronghold", "lithium", "speedrunapi", "starlight", "state-output", "voyager");
7068
whitelist.add("OSX".equals(os) ? "sodiummac" : "sodium");
7169

72-
Set<String> proWhitelist = Sets.newHashSet("standardsettings", "antiresourcereload");
70+
Set<String> proWhitelist = Sets.newHashSet("standardsettings");
7371
proWhitelist.addAll(whitelist);
74-
Set<String> allWhitelist = Sets.newHashSet("atum", "state-output", "worldpreview", "forceport", "sleepbackground", "speedrunigt");
72+
Set<String> allWhitelist = Sets.newHashSet("atum", "chunkumulator", "forceport", "mcsrfairplay", "seedqueue", "sleepbackground", "speedrunigt", "worldpreview");
7573
allWhitelist.addAll(proWhitelist);
7674
Set<String> rankedOptions = Set.of("", "Pro", "All");
7775

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
package com.redlimerl.mcsr.helper;
22

33
import com.google.gson.JsonArray;
4-
import com.google.gson.JsonElement;
54
import com.google.gson.JsonObject;
65
import com.redlimerl.mcsr.MCSRModLoader;
76
import com.redlimerl.mcsr.mod.FabricLoader;
87
import com.redlimerl.mcsr.mod.ModInfo;
98

10-
import java.io.ByteArrayInputStream;
119
import java.io.FileOutputStream;
1210
import java.io.IOException;
1311
import java.nio.charset.StandardCharsets;
14-
import java.nio.file.Path;
12+
import java.nio.file.*;
1513
import java.text.SimpleDateFormat;
1614
import java.util.*;
17-
import java.util.stream.Collectors;
1815
import java.util.zip.ZipEntry;
1916
import java.util.zip.ZipOutputStream;
2017

@@ -36,12 +33,7 @@ public static JsonObject convertPack(String name, String gameVersion, FabricLoad
3633
for (ModInfo.ModVersion version : mod.versions()) {
3734
for (String s : version.target_version()) {
3835
if (s.equals("1.16.1")) {
39-
if (version.url().startsWith("https://github.com")) {
40-
jsonArray.add(getGithubMeta(version.url()));
41-
}
42-
if (version.url().startsWith("https://cdn.modrinth.com")) {
43-
jsonArray.add(getModrinthMeta(version.hash()));
44-
}
36+
jsonArray.add(getFileObject(version.url().substring(version.url().lastIndexOf("/") + 1), version.sha1(), version.sha512(), version.url(), version.size()));
4537
continue mod;
4638
}
4739
}
@@ -76,49 +68,11 @@ public static JsonObject getFileObject(String fileName, String sha1, String sha5
7668
}
7769

7870
public static void writeZipFile(Path path, String packData) throws IOException {
71+
Files.createDirectories(path.getParent());
7972
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(path.toFile()));
8073
out.putNextEntry(new ZipEntry("modrinth.index.json"));
8174
out.write(packData.getBytes(StandardCharsets.UTF_8));
8275
out.closeEntry();
8376
out.close();
8477
}
85-
86-
private static final Map<String, JsonElement> cachedApi = new HashMap<>();
87-
private static final Map<String, String> cachedSha1 = new HashMap<>();
88-
private static final Map<String, String> cachedSha512 = new HashMap<>();
89-
public static JsonObject getGithubMeta(String url) throws IOException {
90-
Map.Entry<String, String> apiVersion = Map.entry("X-GitHub-Api-Version", "2022-11-28");
91-
Map.Entry<String, String> githubToken = Map.entry("Authorization", "token " + MCSRModLoader.GITHUB_TOKEN);
92-
93-
url = url.replaceAll("https://github.com/Minecraft-Java-Edition-Speedrunning/legal-mods/raw/(\\w*)/", "https://api.github.com/repos/Minecraft-Java-Edition-Speedrunning/legal-mods/contents/");
94-
url = Arrays.stream(url.split("/")).filter(path -> !path.endsWith(".jar")).collect(Collectors.joining("/")) + "?ref=main";
95-
JsonArray jsonArray = cachedApi.containsKey(url) ? cachedApi.get(url).getAsJsonArray() : HttpRequestHelper.getJsonFromUrl(url, apiVersion, githubToken).getAsJsonArray();
96-
cachedApi.putIfAbsent(url, jsonArray);
97-
98-
for (JsonElement jsonElement : jsonArray) {
99-
JsonObject data = jsonElement.getAsJsonObject();
100-
String download = data.get("download_url").getAsString();
101-
ByteArrayInputStream fileInputStream = HttpRequestHelper.getInputStreamFromUrl(download);
102-
String sha1 = cachedSha1.containsKey(download) ? cachedSha1.get(download) : ShaHelper.getSha1FromInputStream(fileInputStream);
103-
fileInputStream.reset();
104-
cachedSha1.putIfAbsent(download, sha1);
105-
String sha512 = cachedSha512.containsKey(download) ? cachedSha512.get(download) : ShaHelper.getSha512FromInputStream(fileInputStream);
106-
cachedSha512.putIfAbsent(download, sha512);
107-
return getFileObject(data.get("name").getAsString(), sha1, sha512, data.get("download_url").getAsString(), data.get("size").getAsInt());
108-
}
109-
110-
return null;
111-
}
112-
public static JsonObject getModrinthMeta(String sha512) throws IOException {
113-
String url = "https://api.modrinth.com/v2/version_file/" + sha512 + "?algorithm=sha512";
114-
JsonObject jsonObject = cachedApi.containsKey(url) ? cachedApi.get(url).getAsJsonObject() : HttpRequestHelper.getJsonFromUrl(url).getAsJsonObject();
115-
cachedApi.putIfAbsent(url, jsonObject);
116-
117-
for (JsonElement jsonElement : jsonObject.getAsJsonArray("files")) {
118-
JsonObject data = jsonElement.getAsJsonObject();
119-
return getFileObject(data.get("filename").getAsString(), data.getAsJsonObject("hashes").get("sha1").getAsString(), sha512, data.get("url").getAsString(), data.get("size").getAsInt());
120-
}
121-
122-
return null;
123-
}
12478
}

ModFileLoader/src/main/java/com/redlimerl/mcsr/mod/ModInfo.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,16 @@ public String toString() {
5252
public static final class ModVersion {
5353
private List<String> target_version;
5454
private String url;
55-
private String hash;
55+
private String sha1;
56+
private String sha512;
57+
private int size;
5658

57-
public ModVersion(List<String> target_version, String url, String hash) {
59+
public ModVersion(List<String> target_version, String url, String sha1, String sha512, int size) {
5860
this.target_version = target_version;
5961
this.url = url;
60-
this.hash = hash;
62+
this.sha1 = sha1;
63+
this.sha512 = sha512;
64+
this.size = size;
6165
}
6266

6367
public List<String> target_version() {
@@ -68,8 +72,16 @@ public String url() {
6872
return url;
6973
}
7074

71-
public String hash() {
72-
return hash;
75+
public String sha1() {
76+
return sha1;
77+
}
78+
79+
public String sha512() {
80+
return sha512;
81+
}
82+
83+
public int size() {
84+
return size;
7385
}
7486

7587
@Override
@@ -79,20 +91,24 @@ public boolean equals(Object obj) {
7991
var that = (ModVersion) obj;
8092
return Objects.equals(this.target_version, that.target_version) &&
8193
Objects.equals(this.url, that.url) &&
82-
Objects.equals(this.hash, that.hash);
94+
Objects.equals(this.sha1, that.sha1) &&
95+
Objects.equals(this.sha512, that.sha512) &&
96+
this.size == that.size;
8397
}
8498

8599
@Override
86100
public int hashCode() {
87-
return Objects.hash(target_version, url, hash);
101+
return Objects.hash(target_version, url, sha1, sha512, size);
88102
}
89103

90104
@Override
91105
public String toString() {
92106
return "ModVersion[" +
93107
"target_version=" + target_version + ", " +
94108
"url=" + url + ", " +
95-
"hash=" + hash + ']';
109+
"sha1=" + sha1 + ", " +
110+
"sha512=" + sha512 + ", " +
111+
"size=" + size + ']';
96112
}
97113

98114
}
444 Bytes
Binary file not shown.
24 Bytes
Binary file not shown.
161 Bytes
Binary file not shown.
593 Bytes
Binary file not shown.
172 Bytes
Binary file not shown.
309 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)