-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more possible visitors during remapping and start moving more api…
… under our new group
- Loading branch information
1 parent
1ea4a4d
commit 07039b8
Showing
9 changed files
with
320 additions
and
72 deletions.
There are no files selected for viewing
30 changes: 12 additions & 18 deletions
30
src/main/java/fr/catcore/modremapperapi/remapping/MRAClassVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 98 additions & 28 deletions
126
src/main/java/fr/catcore/modremapperapi/remapping/MRAMethodVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,144 @@ | ||
package fr.catcore.modremapperapi.remapping; | ||
|
||
import io.github.fabriccompatibiltylayers.modremappingapi.impl.VisitorInfosImpl; | ||
import org.objectweb.asm.MethodVisitor; | ||
import org.objectweb.asm.Opcodes; | ||
|
||
import java.util.Map; | ||
|
||
public class MRAMethodVisitor extends MethodVisitor { | ||
private final VisitorInfos infos; | ||
public class MRAMethodVisitor extends MethodVisitor implements Opcodes { | ||
private final VisitorInfosImpl infos; | ||
private final String className; | ||
protected MRAMethodVisitor(MethodVisitor methodVisitor, VisitorInfos visitorInfos, String className) { | ||
protected MRAMethodVisitor(MethodVisitor methodVisitor, VisitorInfosImpl visitorInfos, String className) { | ||
super(Opcodes.ASM9, methodVisitor); | ||
this.infos = visitorInfos; | ||
this.className = className; | ||
} | ||
|
||
@Override | ||
public void visitTypeInsn(int opcode, String type) { | ||
VisitorInfos.Type superType = new VisitorInfos.Type(type); | ||
String currentType = type; | ||
|
||
for (Map.Entry<VisitorInfos.Type, VisitorInfos.Type> entry : infos.METHOD_TYPE.entrySet()) { | ||
if (entry.getKey().type.equals(type)) { | ||
superType = entry.getValue(); | ||
break; | ||
} | ||
boolean skip = false; | ||
|
||
if (opcode == NEW && infos.INSTANTIATION.containsKey(type)) { | ||
currentType = infos.INSTANTIATION.get(type); | ||
skip = true; | ||
} | ||
|
||
if (!skip && infos.METHOD_TYPE.containsKey(type)) { | ||
currentType = infos.METHOD_TYPE.get(type); | ||
} | ||
|
||
super.visitTypeInsn(opcode, superType.type); | ||
super.visitTypeInsn(opcode, currentType); | ||
} | ||
|
||
@Override | ||
public void visitFieldInsn(int opcode, String owner, String name, String descriptor) { | ||
VisitorInfos.MethodNamed superType = new VisitorInfos.MethodNamed(owner, name); | ||
String currentOwner = owner; | ||
String currentName = name; | ||
String currentDescriptor = descriptor; | ||
|
||
if (infos.FIELD_REF.containsKey(owner)) { | ||
Map<String, Map<String, io.github.fabriccompatibiltylayers.modremappingapi.api.VisitorInfos.FullClassMember>> fields = infos.FIELD_REF.get(owner); | ||
|
||
Map<String, io.github.fabriccompatibiltylayers.modremappingapi.api.VisitorInfos.FullClassMember> args = fields.get(name); | ||
|
||
if (args == null) { | ||
args = fields.get(""); | ||
} | ||
|
||
for (Map.Entry<VisitorInfos.MethodNamed, VisitorInfos.MethodNamed> entry : infos.METHOD_FIELD.entrySet()) { | ||
if (entry.getKey().owner.equals(owner)) { | ||
if (entry.getKey().name.isEmpty() || entry.getKey().name.equals(name)) { | ||
superType = entry.getValue(); | ||
if (args != null) { | ||
io.github.fabriccompatibiltylayers.modremappingapi.api.VisitorInfos.FullClassMember classMember = args.get(descriptor); | ||
|
||
if (classMember == null) { | ||
classMember = args.get(""); | ||
} | ||
|
||
if (classMember != null) { | ||
currentOwner = classMember.owner; | ||
currentName = classMember.name; | ||
currentDescriptor = classMember.desc; | ||
} | ||
} | ||
} | ||
|
||
super.visitFieldInsn(opcode, superType.owner, superType.name.isEmpty() ? name : superType.name, descriptor); | ||
if (currentName.isEmpty()) { | ||
currentName = name; | ||
} | ||
|
||
if (currentDescriptor == null || currentDescriptor.isEmpty()) { | ||
currentDescriptor = descriptor; | ||
} | ||
|
||
super.visitFieldInsn(opcode, currentOwner, currentName, currentDescriptor); | ||
} | ||
|
||
@Override | ||
public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) { | ||
VisitorInfos.MethodNamed superType = new VisitorInfos.MethodNamed(owner, name); | ||
int currentOpcode = opcode; | ||
String currentOwner = owner; | ||
String currentName = name; | ||
String currentDescriptor = descriptor; | ||
|
||
for (Map.Entry<VisitorInfos.MethodNamed, VisitorInfos.MethodNamed> entry : infos.METHOD_METHOD.entrySet()) { | ||
if (entry.getKey().owner.equals(owner)) { | ||
if (entry.getKey().name.isEmpty() || entry.getKey().name.equals(name)) { | ||
superType = entry.getValue(); | ||
boolean skip = false; | ||
|
||
if (opcode == INVOKESPECIAL && infos.INSTANTIATION.containsKey(owner) && name.equals("<init>")) { | ||
currentOwner = infos.INSTANTIATION.get(owner); | ||
skip = true; | ||
} | ||
|
||
if (!skip && (opcode == INVOKEVIRTUAL || opcode == INVOKESTATIC)) { | ||
if (infos.METHOD_INVOCATION.containsKey(owner)) { | ||
Map<String, Map<String, io.github.fabriccompatibiltylayers.modremappingapi.api.VisitorInfos.FullClassMember>> methods = infos.METHOD_INVOCATION.get(owner); | ||
|
||
Map<String, io.github.fabriccompatibiltylayers.modremappingapi.api.VisitorInfos.FullClassMember> args = methods.get(currentName); | ||
|
||
if (args == null) { | ||
args = methods.get(""); | ||
} | ||
|
||
if (args != null) { | ||
io.github.fabriccompatibiltylayers.modremappingapi.api.VisitorInfos.FullClassMember fullClassMember = args.get(currentDescriptor); | ||
|
||
if (fullClassMember == null) { | ||
fullClassMember = args.get(""); | ||
} | ||
|
||
if (fullClassMember != null) { | ||
currentOwner = fullClassMember.owner; | ||
currentName = fullClassMember.name; | ||
currentDescriptor = fullClassMember.desc; | ||
|
||
if (fullClassMember.isStatic != null) currentOpcode = fullClassMember.isStatic ? INVOKESTATIC : INVOKEVIRTUAL; | ||
} | ||
} | ||
} | ||
} | ||
|
||
super.visitMethodInsn(opcode, superType.owner, superType.name.isEmpty() ? name : superType.name, descriptor, isInterface); | ||
if (currentName.isEmpty()) { | ||
currentName = name; | ||
} | ||
|
||
if (currentDescriptor == null || currentDescriptor.isEmpty()) { | ||
currentDescriptor = descriptor; | ||
} | ||
|
||
super.visitMethodInsn(currentOpcode, currentOwner, currentName, currentDescriptor, isInterface); | ||
} | ||
|
||
@Override | ||
public void visitLdcInsn(Object value) { | ||
VisitorInfos.MethodValue val = new VisitorInfos.MethodValue(this.className, value); | ||
Object currentValue = value; | ||
|
||
if (infos.LDC.containsKey(this.className)) { | ||
Map<Object, Object> map = infos.LDC.get(this.className); | ||
|
||
for (Map.Entry<VisitorInfos.MethodValue, VisitorInfos.MethodValue> entry : infos.METHOD_LDC.entrySet()) { | ||
if (entry.getKey().value.equals(value)) { | ||
val = entry.getValue(); | ||
break; | ||
if (map.containsKey(value)) { | ||
currentValue = map.get(value); | ||
} | ||
} | ||
|
||
super.visitLdcInsn(val.value); | ||
super.visitLdcInsn(currentValue); | ||
} | ||
} |
5 changes: 3 additions & 2 deletions
5
src/main/java/fr/catcore/modremapperapi/remapping/MRAPostApplyVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
package fr.catcore.modremapperapi.remapping; | ||
|
||
import io.github.fabriccompatibiltylayers.modremappingapi.impl.VisitorInfosImpl; | ||
import net.fabricmc.tinyremapper.TinyRemapper; | ||
import net.fabricmc.tinyremapper.api.TrClass; | ||
import org.objectweb.asm.ClassVisitor; | ||
|
||
public class MRAPostApplyVisitor implements TinyRemapper.ApplyVisitorProvider { | ||
private VisitorInfos infos; | ||
private VisitorInfosImpl infos; | ||
@Override | ||
public ClassVisitor insertApplyVisitor(TrClass cls, ClassVisitor next) { | ||
final String className = cls.getName(); | ||
return new MRAClassVisitor(next, infos, className); | ||
} | ||
|
||
public void setInfos(VisitorInfos infos) { | ||
public void setInfos(VisitorInfosImpl infos) { | ||
this.infos = infos; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.