refactor parameter remappers to be subclasses of *Visitor instead of *Remapper
All checks were successful
Publish to snapshot maven / build (push) Successful in 24s

This commit is contained in:
moehreag 2024-08-28 10:41:16 +02:00
parent 1fff5c75f6
commit d68f4abea0
4 changed files with 24 additions and 13 deletions

View file

@ -8,14 +8,14 @@ plugins {
} }
group = "dev.frogmc" group = "dev.frogmc"
version = "0.0.1-alpha.12" version = "0.0.1-alpha.13"
repositories { repositories {
mavenCentral() mavenCentral()
} }
dependencies { 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:9.7")
implementation("org.ow2.asm:asm-commons:9.7") implementation("org.ow2.asm:asm-commons:9.7")
} }

View file

@ -31,12 +31,13 @@ public class Thyroxine {
private static boolean SYSOUT = false; private static boolean SYSOUT = false;
public static void run(String minecraftVersion, Path inputJar, Path outputJar, boolean skipMetaInf, boolean renameParameters) throws IOException, InterruptedException { 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, MappingBundle data = MojmapProvider.get(minecraftVersion,
outputJar.resolveSibling("client-" + minecraftVersion + ".txt")).orElseThrow().reverse(); out.resolveSibling("client-" + minecraftVersion + ".txt")).orElseThrow().reverse();
MappingBundle parchment = null; MappingBundle parchment = null;
if (renameParameters) { if (renameParameters) {
parchment = ParchmentProvider.getParchment(minecraftVersion, outputJar.getParent()); parchment = ParchmentProvider.getParchment(minecraftVersion, out.getParent());
} }
MappingBundle result; MappingBundle result;
@ -47,7 +48,7 @@ public class Thyroxine {
} }
SYSOUT = true; SYSOUT = true;
remap(result, inputJar, outputJar, skipMetaInf, renameParameters, "official", "named"); remap(result, inputJar, out, skipMetaInf, renameParameters, "official", "named");
SYSOUT = false; SYSOUT = false;
} }
@ -61,7 +62,8 @@ public class Thyroxine {
public static void remap(MappingData data, Path inputJar, Path outputJar, boolean skipMetaInf, boolean renameParameters, Path... context) 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( List<RemappingStep> steps = List.of(
(cv, mapper) -> renameParameters ? new ParameterClassRemapper(cv, mapper, data) : new ClassRemapper(cv, mapper) ClassRemapper::new,
(cv, mapper) -> renameParameters ? new ParameterClassRemapper(cv, mapper, data) : cv
); );
remap(data, inputJar, outputJar, skipMetaInf, steps, context); remap(data, inputJar, outputJar, skipMetaInf, steps, context);
} }

View file

@ -8,17 +8,25 @@ import dev.frogmc.thyroxine.api.data.MappingData;
import dev.frogmc.thyroxine.api.data.Member; import dev.frogmc.thyroxine.api.data.Member;
import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.commons.ClassRemapper;
import org.objectweb.asm.commons.Remapper; import org.objectweb.asm.commons.Remapper;
public class ParameterClassRemapper extends ClassRemapper { public class ParameterClassRemapper extends ClassVisitor {
private final MappingData data; private final MappingData data;
private final Remapper remapper;
private String className;
public ParameterClassRemapper(ClassVisitor classVisitor, Remapper remapper, MappingData data) { public ParameterClassRemapper(ClassVisitor classVisitor, Remapper remapper, MappingData data) {
super(Constants.ASM_VERSION, classVisitor, remapper); super(Constants.ASM_VERSION, classVisitor);
this.remapper = remapper;
this.data = data; 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 @Override
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) { public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
String remappedDescriptor = remapper.mapMethodDesc(descriptor); 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); 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(); 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);
} }
} }

View file

@ -9,15 +9,16 @@ import dev.frogmc.thyroxine.Constants;
import org.objectweb.asm.Label; import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Type; import org.objectweb.asm.Type;
import org.objectweb.asm.commons.MethodRemapper;
import org.objectweb.asm.commons.Remapper; 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 Map<Integer, String> parameters;
private final Set<String> usedLocalNames = new HashSet<>(); private final Set<String> usedLocalNames = new HashSet<>();
public ParameterMethodRemapper(MethodVisitor methodVisitor, Remapper remapper, Map<Integer, String> parameters) { public ParameterMethodRemapper(MethodVisitor methodVisitor, Remapper remapper, Map<Integer, String> parameters) {
super(Constants.ASM_VERSION, methodVisitor, remapper); super(Constants.ASM_VERSION, methodVisitor);
this.remapper = remapper;
this.parameters = parameters; this.parameters = parameters;
} }