reindent ProguardParser, allow for mojmap caching and add .editorconfig
All checks were successful
Publish to snapshot maven / build (push) Successful in 13s
All checks were successful
Publish to snapshot maven / build (push) Successful in 13s
This commit is contained in:
parent
8ce3afa7d6
commit
087234d3f9
9
.editorconfig
Normal file
9
.editorconfig
Normal file
|
@ -0,0 +1,9 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
tab_width = 4
|
||||
trim_trailing_whitespace = true
|
||||
indent_style = tab
|
|
@ -25,7 +25,7 @@ import org.objectweb.asm.commons.ClassRemapper;
|
|||
public class NonsenseRemapper {
|
||||
|
||||
public static void run(String minecraftVersion, Path inputJar, Path outputJar, boolean skipMetaInf, boolean renameParameters) throws IOException, InterruptedException {
|
||||
MappingData data = ProguardParser.read(MojmapProvider.get(minecraftVersion).orElseThrow()).reverse();
|
||||
MappingData data = ProguardParser.read(MojmapProvider.get(minecraftVersion, outputJar.resolveSibling("client-"+minecraftVersion+".txt")).orElseThrow()).reverse();
|
||||
Mapper mapper = new Mapper(data);
|
||||
|
||||
|
||||
|
|
|
@ -1,97 +1,97 @@
|
|||
package org.ecorous.esnesnon.nonsense_remapper.parser;
|
||||
|
||||
import org.ecorous.esnesnon.nonsense_remapper.api.data.Member;
|
||||
import org.ecorous.esnesnon.nonsense_remapper.api.data.MappingData;
|
||||
import org.ecorous.esnesnon.nonsense_remapper.api.data.Member;
|
||||
|
||||
public class ProguardParser {
|
||||
|
||||
public static MappingData read(String mappings) {
|
||||
String[] lines = mappings.split("\n");
|
||||
public static MappingData read(String mappings) {
|
||||
String[] lines = mappings.split("\n");
|
||||
|
||||
MappingData data = new MappingData();
|
||||
String currentClass = null;
|
||||
for (String line : lines) {
|
||||
if (line.contains("#")) {
|
||||
line = line.substring(0, line.indexOf('#'));
|
||||
}
|
||||
MappingData data = new MappingData();
|
||||
String currentClass = null;
|
||||
for (String line : lines) {
|
||||
if (line.contains("#")) {
|
||||
line = line.substring(0, line.indexOf('#'));
|
||||
}
|
||||
|
||||
line = line.trim();
|
||||
line = line.trim();
|
||||
|
||||
if (line.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (line.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int arrowIndex = line.indexOf("->");
|
||||
if (arrowIndex == -1) {
|
||||
throw new IllegalStateException("Missing arrow in mapping");
|
||||
}
|
||||
int arrowIndex = line.indexOf("->");
|
||||
if (arrowIndex == -1) {
|
||||
throw new IllegalStateException("Missing arrow in mapping");
|
||||
}
|
||||
|
||||
String obf = line.substring(0, arrowIndex).trim();
|
||||
String deobf = line.substring(arrowIndex + 2).trim();
|
||||
String obf = line.substring(0, arrowIndex).trim();
|
||||
String deobf = line.substring(arrowIndex + 2).trim();
|
||||
|
||||
if (line.endsWith(":")) {
|
||||
deobf = deobf.substring(0, deobf.length() - 1);
|
||||
currentClass = obf.replace('.', '/');
|
||||
data.classes().put(currentClass, deobf.replace('.', '/'));
|
||||
} else {
|
||||
if (currentClass == null) {
|
||||
throw new IllegalStateException("Member mapping specified before a class");
|
||||
}
|
||||
if (line.endsWith(":")) {
|
||||
deobf = deobf.substring(0, deobf.length() - 1);
|
||||
currentClass = obf.replace('.', '/');
|
||||
data.classes().put(currentClass, deobf.replace('.', '/'));
|
||||
} else {
|
||||
if (currentClass == null) {
|
||||
throw new IllegalStateException("Member mapping specified before a class");
|
||||
}
|
||||
|
||||
int spaceIndex = obf.indexOf(' ');
|
||||
if (spaceIndex == -1) {
|
||||
throw new IllegalStateException("Missing member signature");
|
||||
}
|
||||
int spaceIndex = obf.indexOf(' ');
|
||||
if (spaceIndex == -1) {
|
||||
throw new IllegalStateException("Missing member signature");
|
||||
}
|
||||
|
||||
String type = obf.substring(0, spaceIndex);
|
||||
String signature = obf.substring(spaceIndex + 1);
|
||||
String type = obf.substring(0, spaceIndex);
|
||||
String signature = obf.substring(spaceIndex + 1);
|
||||
|
||||
int colonIndex = type.lastIndexOf(':');
|
||||
if (colonIndex != -1)
|
||||
type = type.substring(colonIndex + 1);
|
||||
int colonIndex = type.lastIndexOf(':');
|
||||
if (colonIndex != -1)
|
||||
type = type.substring(colonIndex + 1);
|
||||
|
||||
if (signature.contains("(") && signature.endsWith(")")) {
|
||||
// method
|
||||
String name = signature.substring(0, signature.indexOf('('));
|
||||
String args = signature.substring(signature.indexOf('(') + 1, signature.length() - 1);
|
||||
StringBuilder descriptor = new StringBuilder();
|
||||
descriptor.append('(');
|
||||
if (!args.isEmpty()) {
|
||||
for (String arg : args.split(",")) {
|
||||
descriptor.append(convertType(arg));
|
||||
}
|
||||
}
|
||||
descriptor.append(')');
|
||||
descriptor.append(convertType(type));
|
||||
if (signature.contains("(") && signature.endsWith(")")) {
|
||||
// method
|
||||
String name = signature.substring(0, signature.indexOf('('));
|
||||
String args = signature.substring(signature.indexOf('(') + 1, signature.length() - 1);
|
||||
StringBuilder descriptor = new StringBuilder();
|
||||
descriptor.append('(');
|
||||
if (!args.isEmpty()) {
|
||||
for (String arg : args.split(",")) {
|
||||
descriptor.append(convertType(arg));
|
||||
}
|
||||
}
|
||||
descriptor.append(')');
|
||||
descriptor.append(convertType(type));
|
||||
|
||||
data.methods().put(new Member(currentClass, name, descriptor.toString()), deobf);
|
||||
} else
|
||||
data.fields().put(new Member(currentClass, signature, convertType(type)), deobf);
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
data.methods().put(new Member(currentClass, name, descriptor.toString()), deobf);
|
||||
} else
|
||||
data.fields().put(new Member(currentClass, signature, convertType(type)), deobf);
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private static String convertType(String type) {
|
||||
int dimensions = 0;
|
||||
while (type.endsWith("[]")) {
|
||||
type = type.substring(0, type.length() - 2);
|
||||
++dimensions;
|
||||
}
|
||||
private static String convertType(String type) {
|
||||
int dimensions = 0;
|
||||
while (type.endsWith("[]")) {
|
||||
type = type.substring(0, type.length() - 2);
|
||||
++dimensions;
|
||||
}
|
||||
|
||||
String result = switch (type) {
|
||||
case "void" -> "V";
|
||||
case "boolean" -> "Z";
|
||||
case "byte" -> "B";
|
||||
case "short" -> "S";
|
||||
case "int" -> "I";
|
||||
case "long" -> "J";
|
||||
case "float" -> "F";
|
||||
case "double" -> "D";
|
||||
case "char" -> "C";
|
||||
default -> 'L' + type.replace('.', '/') + ';';
|
||||
};
|
||||
String result = switch (type) {
|
||||
case "void" -> "V";
|
||||
case "boolean" -> "Z";
|
||||
case "byte" -> "B";
|
||||
case "short" -> "S";
|
||||
case "int" -> "I";
|
||||
case "long" -> "J";
|
||||
case "float" -> "F";
|
||||
case "double" -> "D";
|
||||
case "char" -> "C";
|
||||
default -> 'L' + type.replace('.', '/') + ';';
|
||||
};
|
||||
|
||||
return "[".repeat(dimensions) + result;
|
||||
}
|
||||
return "[".repeat(dimensions) + result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,12 +4,24 @@ import com.google.gson.*;
|
|||
import org.ecorous.esnesnon.nonsense_remapper.Constants;
|
||||
import org.ecorous.esnesnon.nonsense_remapper.HttpHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
|
||||
public class MojmapProvider {
|
||||
|
||||
public static Optional<String> get(String gameVersion) {
|
||||
return HttpHelper.getJson(Constants.VERSION_MANIFEST).map(manifest -> {
|
||||
public static Optional<String> get(String gameVersion, Path cacheFile) {
|
||||
if (Files.exists(cacheFile)){
|
||||
try {
|
||||
return Optional.of(Files.readString(cacheFile, StandardCharsets.UTF_8));
|
||||
} catch (IOException e) {
|
||||
// TODO
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return HttpHelper.getJson(Constants.VERSION_MANIFEST).flatMap(manifest -> {
|
||||
String versionName;
|
||||
if (gameVersion.startsWith("latest-")) {
|
||||
versionName = manifest.get("latest").getAsJsonObject().get(gameVersion.split("-")[1]).getAsString();
|
||||
|
@ -27,10 +39,18 @@ public class MojmapProvider {
|
|||
String mappingsUrl = versionManifest
|
||||
.get("downloads").getAsJsonObject().get("client_mappings").getAsJsonObject().get("url").getAsString();
|
||||
|
||||
return HttpHelper.getString(mappingsUrl).orElseThrow();
|
||||
return HttpHelper.getString(mappingsUrl).map(s -> {
|
||||
try {
|
||||
Files.writeString(cacheFile, s);
|
||||
} catch (IOException e) {
|
||||
// TODO
|
||||
e.printStackTrace();
|
||||
}
|
||||
return s;
|
||||
});
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue