Skip to content

Commit

Permalink
param mapping lvt fix
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolMineman committed Dec 17, 2022
1 parent f1c8d01 commit 118ef1d
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ public Map<BuildModule, ProcessingSource> getRemappedClasses(BuildModule... modu
getCompileDependencies(),
compmappings,
compmappings.getNamespaceId(Namespaces.NAMED),
compmappings.getNamespaceId(Namespaces.INTERMEDIARY)
compmappings.getNamespaceId(Namespaces.INTERMEDIARY),
false
)
).apply(
(in, id) -> sm.get(id).sink(in, id),
Expand Down Expand Up @@ -329,7 +330,7 @@ public byte remappedModsLogicVersion() {
}

public ProcessorChain modRemapChainOverrideOnlyIfYouOverrideRemappedModsRootPathAndLogicVersion(MappingTree tree, String src, String dst, List<Path> cp, Map<ProcessingSource, MavenId> c) {
RemapperProcessor rp = new RemapperProcessor(cp, tree, tree.getNamespaceId(src), tree.getNamespaceId(dst));
RemapperProcessor rp = new RemapperProcessor(cp, tree, tree.getNamespaceId(src), tree.getNamespaceId(dst), false);
return new ProcessorChain(
rp,
new MetaInfFixer(rp),
Expand Down Expand Up @@ -633,7 +634,7 @@ protected RemappedJar createIntermediaryJar() {
Path result = fabricCache().resolve("intermediary").resolve(versionMeta.get().version + "-r" + Recombobulator.getVersion() + "-intermediary-" + intermediaryHash + ".jar");
if (!Files.isRegularFile(result)) {
try (AtomicFile atomicFile = new AtomicFile(result)) {
remapJar(intermediary.get(), Namespaces.OBF, Namespaces.INTERMEDIARY, mergedJar, atomicFile.tempPath, mcClasspathPaths.get());
remapJar(intermediary.get(), Namespaces.OBF, Namespaces.INTERMEDIARY, mergedJar, atomicFile.tempPath, mcClasspathPaths.get(), false);
atomicFile.commit();
}
}
Expand All @@ -649,7 +650,7 @@ protected RemappedJar createRemappedNamedJar() {
Path result = fabricCache().resolve("named").resolve(versionMeta.get().version + "-r" + Recombobulator.getVersion() + "-named-" + mappingHash + ".jar");
if (!Files.isRegularFile(result)) {
try (AtomicFile atomicFile = new AtomicFile(result)) {
remapJar(mappings.get(), Namespaces.INTERMEDIARY, Namespaces.NAMED, intermediaryjar.get().jar, atomicFile.tempPath, mcClasspathPaths.get());
remapJar(mappings.get(), Namespaces.INTERMEDIARY, Namespaces.NAMED, intermediaryjar.get().jar, atomicFile.tempPath, mcClasspathPaths.get(), true);
atomicFile.commit();
}
}
Expand Down Expand Up @@ -700,7 +701,7 @@ protected JavaJarDependency createDecompiledJar() {
return decompiler.getDecompiled(named.jar, decompClasspath(), resultDir, mappings.get(), Namespaces.NAMED).toJavaJarDep(null);
}

public void remapJar(MappingTree mappings, String src, String dst, Path inputJar, Path outputJar, List<Path> classpath) {
public void remapJar(MappingTree mappings, String src, String dst, Path inputJar, Path outputJar, List<Path> classpath, boolean replaceLvt) {
// TinyRemapper.Builder remapperBuilder = TinyRemapper.newRemapper()
// .withMappings(new MappingTreeMappingProvider(mappings, src, dst))
// .withMappings(Jsr2JetbrainsMappingProvider.INSTANCE)
Expand All @@ -716,7 +717,7 @@ public void remapJar(MappingTree mappings, String src, String dst, Path inputJar
ZipProcessingSource source = new ZipProcessingSource(inputJar);
ZipProcessingSink sink = new ZipProcessingSink(outputJar);
) {
new ProcessorChain(new RemapperProcessor(classpath, mappings, mappings.getNamespaceId(src), mappings.getNamespaceId(dst))).apply(sink, source);
new ProcessorChain(new RemapperProcessor(classpath, mappings, mappings.getNamespaceId(src), mappings.getNamespaceId(dst), replaceLvt)).apply(sink, source);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ public class RemapperProcessor implements Processor {
final MappingTree mappingTree;
final int src;
final int dst;
final boolean replaceLvt;

public RemapperProcessor(List<Path> classpath, MappingTree mappingTree, int src, int dst) {
public RemapperProcessor(List<Path> classpath, MappingTree mappingTree, int src, int dst, boolean replaceLvt) {
this.classpath = classpath;
this.mappingTree = mappingTree;
this.src = src;
this.dst = dst;
this.replaceLvt = replaceLvt;
}

@Override
Expand Down Expand Up @@ -114,6 +116,9 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
RecombobulatorRemapper remapper = new RecombobulatorRemapper();
remapper.setClasses(ins);
remapper.setMappings(mappings);
if (replaceLvt) {
remapper.replaceLvtAndParams();
}
ConcurrentLinkedQueue<ProcessingEntry> o = new ConcurrentLinkedQueue<>();
remapper.setOutput(new RemapperOutputConsumer() {
public void outputClass(String path, ClassInfo ci, Object tag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public byte remappedModsLogicVersion() {

@Override
public ProcessorChain modRemapChainOverrideOnlyIfYouOverrideRemappedModsRootPathAndLogicVersion(MappingTree tree, String src, String dst, List<Path> cp, Map<ProcessingSource, MavenId> c) {
RemapperProcessor rp = new RemapperProcessor(cp, tree, tree.getNamespaceId(src), tree.getNamespaceId(dst));
RemapperProcessor rp = new RemapperProcessor(cp, tree, tree.getNamespaceId(src), tree.getNamespaceId(dst), false);
return new ProcessorChain(
rp,
new MetaInfFixer(rp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@
import io.github.coolcrabs.brachyura.recombobulator.AccessFlags;
import io.github.coolcrabs.brachyura.recombobulator.Mutf8Slice;
import io.github.coolcrabs.brachyura.recombobulator.remapper.InheritanceMap.InheritanceGroup;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.fabricmc.mappingio.tree.MappingTree;
import net.fabricmc.mappingio.tree.MappingTree.ClassMapping;
import net.fabricmc.mappingio.tree.MappingTree.FieldMapping;
import net.fabricmc.mappingio.tree.MappingTree.MethodArgMapping;
import net.fabricmc.mappingio.tree.MappingTree.MethodMapping;

public class MappingIoMappings implements Mappings {
public static final boolean LOG_PARAM_CONFLICS = Boolean.getBoolean("recombobulator.logparamconflicts");

private final Map<Mutf8Slice, Mutf8Slice> classMap;
final Int2ObjectOpenHashMap<NameDescPair> methodMap;
final Int2ObjectOpenHashMap<Int2ObjectOpenHashMap<Mutf8Slice>> methodArgMap;
private final InheritanceMap inheritanceMap;
private final ConcurrentHashMap<Mutf8Slice, HashMap<NameDescPair, NameDescPair>> fieldMap;

Expand Down Expand Up @@ -73,9 +78,11 @@ public MappingIoMappings(MappingTree tree, int src, int dst, InheritanceMap inhe
class IntNameDescPairPair {
int key;
NameDescPair value;
Int2ObjectOpenHashMap<Mutf8Slice> params;
}
int size = inheritanceMap.curId;
methodMap = new Int2ObjectOpenHashMap<>(size);
methodArgMap = new Int2ObjectOpenHashMap<>(size);
boolean conflict = false;
ArrayList<Future<List<IntNameDescPairPair>>> futures1 = new ArrayList<>(size);
for (ClassMapping c : tree.getClasses()) {
Expand All @@ -102,6 +109,19 @@ class IntNameDescPairPair {
IntNameDescPairPair indpp = new IntNameDescPairPair();
indpp.key = igroup.id;
indpp.value = mdst;
int s = 0;
for (MethodArgMapping mam : m.getArgs()) {
if (mam.getName(dst) != null) s++;
}
if (s > 0) {
indpp.params = new Int2ObjectOpenHashMap<>(s);
for (MethodArgMapping mam : m.getArgs()) {
String mamn = mam.getName(dst);
if (mamn != null) {
indpp.params.put(mam.getLvIndex(), new Mutf8Slice(mamn));
}
}
}
r.add(indpp);
}
return r;
Expand All @@ -113,9 +133,22 @@ class IntNameDescPairPair {
for (IntNameDescPairPair indpp : indpps) {
NameDescPair old = methodMap.put(indpp.key, indpp.value);
if (old != null && !old.equals(indpp.value)) {
Logger.error("Method mapping confllict {} {} {}", indpp.key, old, indpp.value);
Logger.error("Method mapping confllict {} {} {}", indpp.value, old, indpp.value);
conflict = true;
}
if (indpp.params != null) {
methodArgMap.compute(indpp.key, (k, v) -> {
if (v == null) return indpp.params;
for (Int2ObjectMap.Entry<Mutf8Slice> e : indpp.params.int2ObjectEntrySet()) {
Mutf8Slice o = v.put(e.getIntKey(), e.getValue());
if (o != null && !o.equals(e.getValue())) {
if (LOG_PARAM_CONFLICS) Logger.warn("Param conflict {} {} {}", indpp.value, o, e.getValue());
v.put(e.getIntKey(), o.compareTo(e.getValue()) > 0 ? o : e.getValue());
}
}
return v;
});
}
}
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
Expand Down Expand Up @@ -192,4 +225,15 @@ public NameDescPair mapField(Mutf8Slice srcCls, NameDescPair srcField) {
}
return new NameDescPair(srcField.name, Mappings.remapFieldDescriptor(this, srcField.desc));
}

@Override
public @Nullable Mutf8Slice mapParam(Mutf8Slice srcCls, NameDescPair srcMethod, int lvtIndex) {
InheritanceGroup ig = mapMethod0(srcCls, srcMethod, true);
if (ig != null) {
Int2ObjectOpenHashMap<Mutf8Slice> r1 = methodArgMap.get(ig.id);
if (r1 == null) return null;
return r1.get(lvtIndex);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@

import java.nio.ByteBuffer;

import org.jetbrains.annotations.Nullable;

import io.github.coolcrabs.brachyura.recombobulator.ByteBufferUtil;
import io.github.coolcrabs.brachyura.recombobulator.Mutf8Slice;
import it.unimi.dsi.fastutil.bytes.ByteArrayList;

public interface Mappings {
Mutf8Slice mapClass(Mutf8Slice srcCls);

default NameDescPair mapField(Mutf8Slice srcCls, NameDescPair srcField) {
return new NameDescPair(srcField.name, remapFieldDescriptor(this, srcField.desc));
}

default NameDescPair mapMethod(Mutf8Slice srcCls, NameDescPair srcMethod) {
return new NameDescPair(srcMethod.name, remapMethodDescriptor(this, srcMethod.desc));
}

default @Nullable Mutf8Slice mapParam(Mutf8Slice srcCls, NameDescPair srcMethod, int lvtIndex) {
return null;
}

public static Mutf8Slice remapFieldDescriptor(Mappings mappings, Mutf8Slice desc) {
ByteBuffer b = desc.b;
int start = b.position();
Expand Down
Loading

0 comments on commit 118ef1d

Please sign in to comment.