Compare commits
13 commits
owlsys/tin
...
main
Author | SHA1 | Date | |
---|---|---|---|
moehreag | f5f4cb1d4f | ||
moehreag | e08ed69730 | ||
TheKodeToad | 5ce38092c6 | ||
moehreag | bc47d9cc1a | ||
moehreag | f74fbc5248 | ||
moehreag | d68f4abea0 | ||
moehreag | 1fff5c75f6 | ||
moehreag | 811b4e3611 | ||
moehreag | f90baaef1b | ||
moehreag | 2d524c0eea | ||
moehreag | 69b62e7d0e | ||
moehreag | 25fefae245 | ||
Ecorous | 068928ad3d |
|
@ -8,14 +8,14 @@ plugins {
|
|||
}
|
||||
|
||||
group = "dev.frogmc"
|
||||
version = "0.0.1-alpha.6"
|
||||
version = "0.0.1-alpha.18"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("com.electronwill.night-config:json:3.8.0")
|
||||
implementation("com.electronwill.night-config:json:3.8.1")
|
||||
implementation("org.ow2.asm:asm:9.7")
|
||||
implementation("org.ow2.asm:asm-commons:9.7")
|
||||
}
|
||||
|
|
|
@ -1,8 +1,15 @@
|
|||
package dev.frogmc.thyroxine;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.electronwill.nightconfig.json.JsonParser;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
public final class Constants {
|
||||
public static final String USER_AGENT = "FrogMC Thyroxine/" +
|
||||
Objects.requireNonNullElse(Constants.class.getPackage().getImplementationVersion(), "development") +
|
||||
" <frogmc.dev>";
|
||||
public static final String VERSION_MANIFEST = "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json";
|
||||
public static final JsonParser JSON_PARSER = new JsonParser();
|
||||
public static final int ASM_VERSION = Opcodes.ASM9;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
package dev.frogmc.thyroxine;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.net.http.HttpClient.Redirect;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import com.electronwill.nightconfig.core.UnmodifiableConfig;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
@ -17,21 +16,29 @@ import static dev.frogmc.thyroxine.Constants.JSON_PARSER;
|
|||
@UtilityClass
|
||||
public class HttpHelper {
|
||||
|
||||
private static final Map<String, String> requestCache = new HashMap<>();
|
||||
|
||||
public static Optional<UnmodifiableConfig> getJson(String url) {
|
||||
return getString(url).map(s -> JSON_PARSER.parse(s).unmodifiable());
|
||||
public static UnmodifiableConfig getJson(String url) throws IOException {
|
||||
return JSON_PARSER.parse(getString(url)).unmodifiable();
|
||||
}
|
||||
|
||||
public static Optional<String> getString(String url) {
|
||||
return Optional.ofNullable(requestCache.computeIfAbsent(url, s -> {
|
||||
try (InputStream in = URI.create(url).parseServerAuthority().toURL().openStream()) {
|
||||
return new String(in.readAllBytes(), StandardCharsets.UTF_8);
|
||||
} catch (IOException | URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
// TODO
|
||||
public static String getString(String url) throws IOException {
|
||||
return request(url, HttpResponse.BodyHandlers.ofString()).body();
|
||||
}
|
||||
|
||||
public static void download(String url, Path file) throws IOException {
|
||||
request(url, HttpResponse.BodyHandlers.ofFile(file));
|
||||
}
|
||||
|
||||
private static <T> HttpResponse<T> request(String url, HttpResponse.BodyHandler<T> handler) throws IOException {
|
||||
try (HttpClient client = HttpClient.newBuilder().followRedirects(Redirect.NORMAL).build()) {
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.header("User-Agent", Constants.USER_AGENT)
|
||||
.header("Accept", "*/*")
|
||||
.GET()
|
||||
.uri(URI.create(url))
|
||||
.build();
|
||||
return client.send(request, handler);
|
||||
} catch (InterruptedException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
8
src/main/java/dev/frogmc/thyroxine/RemappingStep.java
Normal file
8
src/main/java/dev/frogmc/thyroxine/RemappingStep.java
Normal file
|
@ -0,0 +1,8 @@
|
|||
package dev.frogmc.thyroxine;
|
||||
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
|
||||
public interface RemappingStep {
|
||||
ClassVisitor run(ClassVisitor previous, Remapper remapper);
|
||||
}
|
|
@ -9,27 +9,34 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import dev.frogmc.thyroxine.api.Mapper;
|
||||
import dev.frogmc.thyroxine.api.ParameterClassRemapper;
|
||||
import dev.frogmc.thyroxine.api.data.MappingBundle;
|
||||
import dev.frogmc.thyroxine.api.data.MappingData;
|
||||
import dev.frogmc.thyroxine.parser.ProguardParser;
|
||||
import dev.frogmc.thyroxine.parser.tiny.TinyV1Parser;
|
||||
import dev.frogmc.thyroxine.parser.tiny.TinyV2Parser;
|
||||
import dev.frogmc.thyroxine.provider.MojmapProvider;
|
||||
import dev.frogmc.thyroxine.provider.ParchmentProvider;
|
||||
import dev.frogmc.thyroxine.api.Mapper;
|
||||
import dev.frogmc.thyroxine.api.data.MappingData;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.commons.ClassRemapper;
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
|
||||
public class Thyroxine {
|
||||
|
||||
private static boolean SYSOUT = false;
|
||||
|
||||
public static void run(String minecraftVersion, Path inputJar, Path outputJar, boolean skipMetaInf, boolean renameParameters) throws IOException, InterruptedException {
|
||||
Path out = outputJar.toAbsolutePath();
|
||||
MappingBundle data = MojmapProvider.get(minecraftVersion,
|
||||
outputJar.resolveSibling("client-" + minecraftVersion + ".txt")).orElseThrow().reverse();
|
||||
out.resolveSibling("client-" + minecraftVersion + ".txt"),
|
||||
out.resolveSibling("server-" + minecraftVersion + ".txt")).reverse();
|
||||
|
||||
MappingBundle parchment = null;
|
||||
if (renameParameters) {
|
||||
parchment = ParchmentProvider.getParchment(minecraftVersion, outputJar.getParent());
|
||||
parchment = ParchmentProvider.getParchment(minecraftVersion, out.getParent());
|
||||
}
|
||||
|
||||
MappingBundle result;
|
||||
|
@ -39,21 +46,33 @@ public class Thyroxine {
|
|||
result = data;
|
||||
}
|
||||
|
||||
remap(result, inputJar, outputJar, skipMetaInf, renameParameters, "official", "named");
|
||||
SYSOUT = true;
|
||||
remap(result, inputJar, out, skipMetaInf, renameParameters, "official", "named");
|
||||
SYSOUT = false;
|
||||
}
|
||||
|
||||
public static void remap(MappingData data, Path inputJar, Path outputJar, boolean skipMetaInf) throws IOException, InterruptedException {
|
||||
remap(data, inputJar, outputJar, skipMetaInf, true);
|
||||
public static void remap(MappingData data, Path inputJar, Path outputJar, boolean skipMetaInf, Path... context) throws IOException, InterruptedException {
|
||||
remap(data, inputJar, outputJar, skipMetaInf, true, context);
|
||||
}
|
||||
|
||||
public static void remap(MappingBundle bundle, Path inputJar, Path outputJar, boolean skipMetaInf, boolean renameParameters, String srcNamespace, String dstNamespace) throws IOException, InterruptedException {
|
||||
remap(bundle.forNamespaces(srcNamespace, dstNamespace), inputJar, outputJar, skipMetaInf, renameParameters);
|
||||
public static void remap(MappingBundle bundle, Path inputJar, Path outputJar, boolean skipMetaInf, boolean renameParameters, String srcNamespace, String dstNamespace, Path... context) throws IOException, InterruptedException {
|
||||
remap(bundle.forNamespaces(srcNamespace, dstNamespace), inputJar, outputJar, skipMetaInf, renameParameters, context);
|
||||
}
|
||||
|
||||
public static void remap(MappingData data, Path inputJar, Path outputJar, boolean skipMetaInf, boolean renameParameters) throws IOException, InterruptedException {
|
||||
public static void remap(MappingData data, Path inputJar, Path outputJar, boolean skipMetaInf, boolean renameParameters, Path... context) throws IOException, InterruptedException {
|
||||
List<RemappingStep> steps = List.of(
|
||||
ClassRemapper::new,
|
||||
(cv, mapper) -> renameParameters ? new ParameterClassRemapper(cv, mapper, data) : cv
|
||||
);
|
||||
remap(data, inputJar, outputJar, skipMetaInf, steps, context);
|
||||
}
|
||||
|
||||
public static void remap(MappingData data, Path inputJar, Path outputJar, boolean skipMetaInf, List<RemappingStep> steps, Path... context) throws IOException, InterruptedException {
|
||||
Files.deleteIfExists(outputJar);
|
||||
|
||||
if (SYSOUT) {
|
||||
System.out.println("Remapping...");
|
||||
}
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
|
@ -61,10 +80,15 @@ public class Thyroxine {
|
|||
FileSystem inFs = FileSystems.newFileSystem(inputJar);
|
||||
FileSystem outFs = FileSystems.newFileSystem(outputJar, Map.of("create", "true"))) {
|
||||
List<Callable<Void>> tasks = new ArrayList<>();
|
||||
Map<Path, FileSystem> contexts = new HashMap<>(context.length + 1);
|
||||
contexts.put(inputJar, inFs);
|
||||
for (Path p : context) {
|
||||
if (!contexts.containsKey(p)) {
|
||||
contexts.put(p, FileSystems.newFileSystem(p));
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, List<String>> lazyParents = new ConcurrentHashMap<>();
|
||||
Mapper mapper = new Mapper(data, className -> lazyParents.computeIfAbsent(className, ignored ->
|
||||
Thyroxine.computeInheritances(className, inFs)));
|
||||
Remapper mapper = createMapper(data, contexts.values());
|
||||
|
||||
Files.walkFileTree(inFs.getPath("/"), new SimpleFileVisitor<>() {
|
||||
|
||||
|
@ -88,12 +112,9 @@ public class Thyroxine {
|
|||
byte[] bytes = Files.readAllBytes(path);
|
||||
ClassReader reader = new ClassReader(bytes);
|
||||
ClassWriter writer = new ClassWriter(0);
|
||||
ClassVisitor remapper = new ClassRemapper(writer, mapper);
|
||||
ClassVisitor visitor;
|
||||
if (renameParameters) {
|
||||
visitor = new ParameterClassRemapper(remapper, mapper, data);
|
||||
} else {
|
||||
visitor = remapper;
|
||||
ClassVisitor visitor = writer;
|
||||
for (RemappingStep pass : steps) {
|
||||
visitor = pass.run(visitor, mapper);
|
||||
}
|
||||
reader.accept(visitor, 0);
|
||||
|
||||
|
@ -119,9 +140,34 @@ public class Thyroxine {
|
|||
|
||||
exec.invokeAll(tasks);
|
||||
|
||||
for (FileSystem fs : contexts.values()) {
|
||||
fs.close();
|
||||
}
|
||||
|
||||
if (SYSOUT) {
|
||||
System.out.printf("Finished remapping (%.2fs)%n", (System.currentTimeMillis() - startTime) / 1000F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Remapper createMapper(MappingData data, Collection<FileSystem> contexts) {
|
||||
Map<String, List<String>> lazyParents = new ConcurrentHashMap<>();
|
||||
MappingData reverseData = data.reverse();
|
||||
return new Mapper(data, className -> lazyParents.computeIfAbsent(className, ignored ->
|
||||
computeInheritances(className, reverseData, contexts)));
|
||||
}
|
||||
|
||||
public static MappingBundle parse(Path mappings) throws IOException {
|
||||
String data = Files.readString(mappings);
|
||||
String header = data.split("\n", 2)[0];
|
||||
if (header.matches("tiny\t+v2\t+.*")) {
|
||||
return TinyV2Parser.parse(data);
|
||||
} else if (TinyV1Parser.HEADER.matcher(header).matches()) {
|
||||
return TinyV1Parser.parse(data);
|
||||
} else {
|
||||
return new MappingBundle(ProguardParser.read(data));
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException, InterruptedException {
|
||||
// temporary
|
||||
|
@ -137,7 +183,6 @@ public class Thyroxine {
|
|||
boolean remapParams = args.length > 3 && hasArg(args, "--remap-parameters");
|
||||
|
||||
run(minecraftVersion, Paths.get(minecraftJar), Paths.get(outJar), removeMetaInf, remapParams);
|
||||
|
||||
}
|
||||
|
||||
private static boolean hasArg(String[] arguments, String arg) {
|
||||
|
@ -149,23 +194,32 @@ public class Thyroxine {
|
|||
return false;
|
||||
}
|
||||
|
||||
private static List<String> computeInheritances(String className, FileSystem inFs){
|
||||
private static List<String> computeInheritances(String className, MappingData reverse, Collection<FileSystem> jars) {
|
||||
try {
|
||||
Path path = inFs.getPath("/" + className + ".class");
|
||||
if (!Files.isRegularFile(path))
|
||||
return List.of();
|
||||
if (reverse.classes().containsKey(className)) {
|
||||
className = reverse.classes().get(className);
|
||||
}
|
||||
List<String> superTypes = new ArrayList<>();
|
||||
for (FileSystem fs : jars) {
|
||||
Path path = fs.getPath("/" + className + ".class");
|
||||
if (!Files.isRegularFile(path)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
byte[] bytes = Files.readAllBytes(path);
|
||||
ClassReader reader = new ClassReader(bytes);
|
||||
List<String> superTypes = new ArrayList<>();
|
||||
reader.accept(new ClassVisitor(Opcodes.ASM9) {
|
||||
reader.accept(new ClassVisitor(Constants.ASM_VERSION) {
|
||||
@Override
|
||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
||||
superTypes.add(superName);
|
||||
if (interfaces != null) {
|
||||
superTypes.addAll(Arrays.asList(interfaces));
|
||||
}
|
||||
if (!"java/lang/Object".equals(superName)) {
|
||||
superTypes.add(superName);
|
||||
}
|
||||
}
|
||||
}, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
|
||||
|
||||
}
|
||||
return superTypes;
|
||||
} catch (IOException error) {
|
||||
throw new Error(error); // not our problem :^) for now
|
||||
|
|
|
@ -60,9 +60,4 @@ public class Mapper extends Remapper {
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mapMethodDesc(String methodDescriptor) {
|
||||
return super.mapMethodDesc(methodDescriptor);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,22 +3,30 @@ package dev.frogmc.thyroxine.api;
|
|||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import dev.frogmc.thyroxine.Constants;
|
||||
import dev.frogmc.thyroxine.api.data.MappingData;
|
||||
import dev.frogmc.thyroxine.api.data.Member;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.commons.ClassRemapper;
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
|
||||
public class ParameterClassRemapper extends ClassRemapper {
|
||||
public class ParameterClassRemapper extends ClassVisitor {
|
||||
private final MappingData data;
|
||||
private final Remapper remapper;
|
||||
|
||||
private String className;
|
||||
public ParameterClassRemapper(ClassVisitor classVisitor, Remapper remapper, MappingData data) {
|
||||
super(Opcodes.ASM9, classVisitor, remapper);
|
||||
super(Constants.ASM_VERSION, classVisitor);
|
||||
this.remapper = remapper;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
||||
this.className = name;
|
||||
super.visit(version, access, name, signature, superName, interfaces);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
|
||||
String remappedDescriptor = remapper.mapMethodDesc(descriptor);
|
||||
|
@ -27,6 +35,6 @@ public class ParameterClassRemapper extends ClassRemapper {
|
|||
|
||||
Member member = new Member(remapper.map(className), remapper.mapMethodName(className, name, descriptor), remappedDescriptor);
|
||||
Map<Integer, String> parameters = data != null ? data.parameters().getOrDefault(member, Collections.emptyMap()) : Collections.emptyMap();
|
||||
return methodVisitor == null ? null : new ParameterMethodRemapper(methodVisitor, remapper, parameters);
|
||||
return new ParameterMethodRemapper(methodVisitor, remapper, parameters);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,24 @@
|
|||
package dev.frogmc.thyroxine.api;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import dev.frogmc.thyroxine.Constants;
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.commons.MethodRemapper;
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
|
||||
public class ParameterMethodRemapper extends MethodRemapper {
|
||||
public class ParameterMethodRemapper extends MethodVisitor {
|
||||
private final Remapper remapper;
|
||||
private final Map<Integer, String> parameters;
|
||||
private final Set<String> usedLocalNames = new HashSet<>();
|
||||
|
||||
public ParameterMethodRemapper(MethodVisitor methodVisitor, Remapper remapper, Map<Integer, String> parameters) {
|
||||
super(Opcodes.ASM9, methodVisitor, remapper);
|
||||
super(Constants.ASM_VERSION, methodVisitor);
|
||||
this.remapper = remapper;
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
|
|
|
@ -163,6 +163,14 @@ public record MappingBundle(List<MappingData> data, List<DocumentationData> docu
|
|||
String w = res;
|
||||
res = d.classes().get(res);
|
||||
if (res == null) {
|
||||
int dollar = w.indexOf("$");
|
||||
if (dollar != -1) {
|
||||
String prefix = d.classes().get(w.substring(0, dollar));
|
||||
if (prefix != null) {
|
||||
res = prefix + w.substring(dollar);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!allowIncomplete) {
|
||||
/*
|
||||
* The mapping set is incomplete at this point.
|
||||
|
|
|
@ -9,7 +9,7 @@ import dev.frogmc.thyroxine.api.data.Member;
|
|||
|
||||
public class TinyV1Parser {
|
||||
|
||||
private static final Pattern HEADER = Pattern.compile("v(?<majorVer>[12]+)\\s\\w*\\s?(?<srcns>\\S+)\\s(?<dstns>\\S+)");
|
||||
public static final Pattern HEADER = Pattern.compile("v(?<majorVer>[12]+)\\s\\w*\\s?(?<srcns>\\S+)\\s(?<dstns>\\S+)");
|
||||
|
||||
public static MappingBundle parse(String mappings) {
|
||||
String[] lines = mappings.split("\n");
|
||||
|
|
|
@ -43,9 +43,9 @@ public class TinyV2Parser {
|
|||
|
||||
if ("c".equals(line[0])) {
|
||||
if (1+ns >= line.length) {
|
||||
do {
|
||||
while (lines[i + 1].startsWith("\t")) {
|
||||
i++;
|
||||
} while (lines[i].startsWith("\t"));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
currentClass = line[ns];
|
||||
|
|
|
@ -1,36 +1,41 @@
|
|||
package dev.frogmc.thyroxine.provider;
|
||||
|
||||
import com.electronwill.nightconfig.core.UnmodifiableConfig;
|
||||
import dev.frogmc.thyroxine.Constants;
|
||||
import dev.frogmc.thyroxine.HttpHelper;
|
||||
import dev.frogmc.thyroxine.api.data.MappingBundle;
|
||||
import dev.frogmc.thyroxine.parser.ProguardParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.electronwill.nightconfig.core.UnmodifiableConfig;
|
||||
import dev.frogmc.thyroxine.Constants;
|
||||
import dev.frogmc.thyroxine.HttpHelper;
|
||||
import dev.frogmc.thyroxine.api.data.MappingBundle;
|
||||
import dev.frogmc.thyroxine.api.data.MappingData;
|
||||
import dev.frogmc.thyroxine.parser.ProguardParser;
|
||||
|
||||
public class MojmapProvider {
|
||||
|
||||
public static Optional<MappingBundle> get(String gameVersion, Path cacheFile) {
|
||||
return getMappings(gameVersion, cacheFile).map(ProguardParser::read).map(MappingBundle::new);
|
||||
public static MappingBundle get(String gameVersion, Path clientCacheFile, Path serverCacheFile) throws IOException {
|
||||
MappingData client = ProguardParser.read(getMappings(gameVersion, "client", clientCacheFile));
|
||||
MappingData server = ProguardParser.read(getMappings(gameVersion, "server", serverCacheFile));
|
||||
client.classes().putAll(server.classes());
|
||||
client.fields().putAll(server.fields());
|
||||
client.methods().putAll(server.methods());
|
||||
client.parameters().putAll(server.parameters());
|
||||
return new MappingBundle(client);
|
||||
}
|
||||
|
||||
public static MappingBundle get(String gameVersion, String env, Path cacheFile) throws IOException {
|
||||
return new MappingBundle(ProguardParser.read(getMappings(gameVersion, env, cacheFile)));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Optional<String> getMappings(String gameVersion, Path cacheFile) {
|
||||
private static String getMappings(String gameVersion, String env, Path cacheFile) throws IOException {
|
||||
if (Files.exists(cacheFile)) {
|
||||
try {
|
||||
return Optional.of(Files.readString(cacheFile, StandardCharsets.UTF_8));
|
||||
} catch (IOException e) {
|
||||
// TODO
|
||||
e.printStackTrace();
|
||||
return Files.readString(cacheFile, StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
return HttpHelper.getJson(Constants.VERSION_MANIFEST).flatMap(manifest -> {
|
||||
UnmodifiableConfig manifest = HttpHelper.getJson(Constants.VERSION_MANIFEST);
|
||||
String versionName;
|
||||
if (gameVersion.startsWith("latest-")) {
|
||||
versionName = (String) ((Map<?, ?>) manifest.get("latest")).get(gameVersion.split("-")[1]);
|
||||
|
@ -43,23 +48,17 @@ public class MojmapProvider {
|
|||
for (UnmodifiableConfig version : (List<UnmodifiableConfig>) manifest.get("versions")) {
|
||||
if (version.get("id").equals(versionName)) {
|
||||
|
||||
UnmodifiableConfig versionManifest = HttpHelper.getJson(version.get("url")).orElseThrow();
|
||||
UnmodifiableConfig versionManifest = HttpHelper.getJson(version.get("url"));
|
||||
String mappingsUrl = ((UnmodifiableConfig) ((UnmodifiableConfig) versionManifest
|
||||
.get("downloads")).get("client_mappings")).get("url");
|
||||
.get("downloads")).get(env+"_mappings")).get("url");
|
||||
|
||||
return HttpHelper.getString(mappingsUrl).map(s -> {
|
||||
try {
|
||||
String s = HttpHelper.getString(mappingsUrl);
|
||||
Files.createDirectories(cacheFile.getParent());
|
||||
Files.writeString(cacheFile, s);
|
||||
} catch (IOException e) {
|
||||
// TODO
|
||||
e.printStackTrace();
|
||||
}
|
||||
return s;
|
||||
});
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
});
|
||||
throw new IllegalArgumentException("Could not find mojmap for the specified version: " + gameVersion + "/"+env+"!");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,12 +2,9 @@ package dev.frogmc.thyroxine.provider;
|
|||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
|
@ -18,6 +15,7 @@ import java.util.*;
|
|||
|
||||
import com.electronwill.nightconfig.core.UnmodifiableConfig;
|
||||
import dev.frogmc.thyroxine.Constants;
|
||||
import dev.frogmc.thyroxine.HttpHelper;
|
||||
import dev.frogmc.thyroxine.api.data.DocumentationData;
|
||||
import dev.frogmc.thyroxine.api.data.MappingBundle;
|
||||
import dev.frogmc.thyroxine.api.data.MappingData;
|
||||
|
@ -61,12 +59,12 @@ public class ParchmentProvider {
|
|||
|
||||
var url = "%s/%s/parchment-%s-%s.zip".formatted(getParchmentUrl(gameVersion), parchmentVer, gameVersion, parchmentVer);
|
||||
if (forceDownload || Files.notExists(cachePath)) {
|
||||
Files.copy(URI.create(url).toURL().openStream(), cachePath);
|
||||
HttpHelper.download(url, cachePath);
|
||||
}
|
||||
|
||||
{
|
||||
try (InputStream input = URI.create(url+".sha512").toURL().openStream()) {
|
||||
var hash = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8)).readLine();
|
||||
try {
|
||||
var hash = HttpHelper.getString(url + ".sha512").split("\n", 2)[0];
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-512");
|
||||
byte[] out = digest.digest(Files.readAllBytes(cachePath));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
|
Loading…
Reference in a new issue