Restructure and simplify some stuff #1
|
@ -1,7 +1,7 @@
|
|||
package io.github.moehreag.mojmap_patcher;
|
||||
|
||||
import io.github.moehreag.mojmap_patcher.load.MojmapLoader;
|
||||
import io.github.moehreag.mojmap_patcher.parser.MojmapParser;
|
||||
import io.github.moehreag.mojmap_patcher.provider.MojmapProvider;
|
||||
import io.github.moehreag.mojmap_patcher.parser.ProguardParser;
|
||||
|
||||
public class MojMapPatcher {
|
||||
|
||||
|
@ -12,9 +12,9 @@ public class MojMapPatcher {
|
|||
} else {
|
||||
version = args[0];
|
||||
}
|
||||
MojmapLoader.get(version).map(MojmapParser::read).ifPresent(s -> {
|
||||
MojmapProvider.get(version).map(ProguardParser::read).ifPresent(s -> {
|
||||
//s.getClassFields().keySet().forEach(System.out::println);
|
||||
s.getClassFields().get("net.minecraft.client.Minecraft").forEach((s1, s2) -> System.out.println(s1 + " -> " + s2));
|
||||
s.classFields().get("net.minecraft.client.Minecraft").forEach((s1, s2) -> System.out.println(s1 + " -> " + s2));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package io.github.moehreag.mojmap_patcher.api;
|
||||
|
||||
import io.github.moehreag.mojmap_patcher.api.data.Data;
|
||||
import io.github.moehreag.mojmap_patcher.api.data.MappingData;
|
||||
import io.github.moehreag.mojmap_patcher.api.data.Field;
|
||||
import io.github.moehreag.mojmap_patcher.api.data.Method;
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
|
@ -11,18 +11,18 @@ import java.util.Optional;
|
|||
|
||||
public class Mapper extends Remapper {
|
||||
|
||||
private Data data;
|
||||
private MappingData data;
|
||||
|
||||
public static Mapper load() {
|
||||
|
||||
throw new UnsupportedOperationException("TODO");
|
||||
}
|
||||
|
||||
public String mapClass(String name) {
|
||||
return data.getClasses().getOrDefault(name, name);
|
||||
return data.classes().getOrDefault(name, name);
|
||||
}
|
||||
|
||||
private Optional<Method> mapMethodInternal(String owner, String name, String descriptor) {
|
||||
for (Map.Entry<Method, Method> entry : data.getClassMethods().getOrDefault(owner, Collections.emptyMap()).entrySet()) {
|
||||
for (Map.Entry<Method, Method> entry : data.classMethods().getOrDefault(owner, Collections.emptyMap()).entrySet()) {
|
||||
Method from = entry.getKey();
|
||||
Method to = entry.getValue();
|
||||
|
||||
|
@ -38,7 +38,7 @@ public class Mapper extends Remapper {
|
|||
}
|
||||
|
||||
private Optional<Field> mapFieldInternal(String owner, String name, String descriptor) {
|
||||
for (Map.Entry<Field, Field> entry : data.getClassFields().getOrDefault(owner, Collections.emptyMap()).entrySet()) {
|
||||
for (Map.Entry<Field, Field> entry : data.classFields().getOrDefault(owner, Collections.emptyMap()).entrySet()) {
|
||||
Field from = entry.getKey();
|
||||
Field to = entry.getValue();
|
||||
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
package io.github.moehreag.mojmap_patcher.api.data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface Data {
|
||||
|
||||
Map<String, String> getClasses();
|
||||
|
||||
Map<String, Map<Method, Method>> getClassMethods();
|
||||
|
||||
Map<String, Map<Field, Field>> getClassFields();
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package io.github.moehreag.mojmap_patcher.api.data;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public record MappingData(
|
||||
// IntelliJank, stop putting 8 spaces >:(
|
||||
Map<String, String> classes,
|
||||
Map<String, Map<Method, Method>> classMethods,
|
||||
Map<String, Map<Field, Field>> classFields
|
||||
) {
|
||||
|
||||
public MappingData() {
|
||||
this(new HashMap<>(), new HashMap<>(), new HashMap<>());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package io.github.moehreag.mojmap_patcher.data;
|
||||
|
||||
import io.github.moehreag.mojmap_patcher.api.data.Field;
|
||||
import io.github.moehreag.mojmap_patcher.api.data.Method;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class MojmapData implements io.github.moehreag.mojmap_patcher.api.data.Data {
|
||||
|
||||
private final Map<String, String> classes = new HashMap<>();
|
||||
private final Map<String, Map<Method, Method>> classMethods = new HashMap<>();
|
||||
private final Map<String, Map<Field, Field>> classFields = new HashMap<>();
|
||||
|
||||
}
|
|
@ -2,17 +2,17 @@ package io.github.moehreag.mojmap_patcher.parser;
|
|||
|
||||
import io.github.moehreag.mojmap_patcher.Constants;
|
||||
import io.github.moehreag.mojmap_patcher.api.data.Field;
|
||||
import io.github.moehreag.mojmap_patcher.api.data.MappingData;
|
||||
import io.github.moehreag.mojmap_patcher.api.data.Method;
|
||||
import io.github.moehreag.mojmap_patcher.data.MojmapData;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class MojmapParser {
|
||||
public class ProguardParser {
|
||||
|
||||
public static MojmapData read(String mappings) {
|
||||
public static MappingData read(String mappings) {
|
||||
String[] lines = mappings.split("\n");
|
||||
|
||||
MojmapData data = new MojmapData();
|
||||
MappingData data = new MappingData();
|
||||
String currentClass = null;
|
||||
for (String line : lines) {
|
||||
if (line.startsWith("#")) { // Filter out comments
|
||||
|
@ -30,15 +30,15 @@ public class MojmapParser {
|
|||
String[] method = deobf.split(":");
|
||||
String[] descriptor = method[2].split(" ");
|
||||
int bracket = descriptor[1].indexOf("(");
|
||||
data.getClassMethods().computeIfAbsent(currentClass, s -> new HashMap<>()).put(new Method(Integer.parseInt(method[0]), Integer.parseInt(method[1]), obf, descriptor[1].substring(0, bracket), descriptor[1].substring(bracket + 1)),
|
||||
data.classMethods().computeIfAbsent(currentClass, s -> new HashMap<>()).put(new Method(Integer.parseInt(method[0]), Integer.parseInt(method[1]), obf, descriptor[1].substring(0, bracket), descriptor[1].substring(bracket + 1)),
|
||||
new Method(Integer.parseInt(method[0]), Integer.parseInt(method[1]), descriptor[0], descriptor[1].substring(0, bracket), descriptor[1].substring(bracket + 1)));
|
||||
} else {
|
||||
String[] field = deobf.split(" ");
|
||||
data.getClassFields().computeIfAbsent(currentClass, s -> new HashMap<>()).put(new Field(field[1], obf), new Field(field[1], field[0]));
|
||||
data.classFields().computeIfAbsent(currentClass, s -> new HashMap<>()).put(new Field(field[1], obf), new Field(field[1], field[0]));
|
||||
}
|
||||
} else { // It's a class mapping
|
||||
currentClass = deobf;
|
||||
data.getClasses().put(obf, deobf);
|
||||
data.classes().put(obf, deobf);
|
||||
}
|
||||
}
|
||||
return data;
|
|
@ -1,4 +1,4 @@
|
|||
package io.github.moehreag.mojmap_patcher.load;
|
||||
package io.github.moehreag.mojmap_patcher.provider;
|
||||
|
||||
import com.google.gson.*;
|
||||
import io.github.moehreag.mojmap_patcher.Constants;
|
||||
|
@ -6,7 +6,7 @@ import io.github.moehreag.mojmap_patcher.HttpHelper;
|
|||
|
||||
import java.util.Optional;
|
||||
|
||||
public class MojmapLoader {
|
||||
public class MojmapProvider {
|
||||
|
||||
public static Optional<String> get(String gameVersion) {
|
||||
return HttpHelper.getJson(Constants.VERSION_MANIFEST).map(manifest -> {
|
Loading…
Reference in a new issue