SrgMerger: Add support for comments and parameters

This commit is contained in:
Juuz
2022-09-06 20:39:30 +03:00
parent 68bf76f328
commit 589ff323e8
6 changed files with 46 additions and 2 deletions

View File

@@ -145,9 +145,11 @@ public final class SrgMerger {
for (MappingTree.ClassMapping srgClass : srg.getClasses()) {
String[] dstNames = createDstNameArray(srgClass);
MappingTree.ClassMapping tinyClass = src.getClass(srgClass.getSrcName());
String comment = null;
if (tinyClass != null) {
copyDstNames(dstNames, tinyClass);
comment = tinyClass.getComment();
} else if (lenient) {
// Tiny class not found, we'll just use srg names
fillMappings(dstNames, srgClass);
@@ -156,6 +158,7 @@ public final class SrgMerger {
}
flatOutput.visitClass(srgClass.getSrcName(), dstNames);
if (comment != null) flatOutput.visitClassComment(srgClass.getSrcName(), comment);
for (MappingTree.FieldMapping field : srgClass.getFields()) {
mergeField(srgClass, field, tinyClass);
@@ -175,6 +178,7 @@ public final class SrgMerger {
String[] dstNames = createDstNameArray(srgField);
MappingTree.FieldMapping tinyField = null;
String srcDesc = srgField.getSrcDesc();
String comment = null;
if (tinyClass != null) {
if (srcDesc != null) {
@@ -189,12 +193,14 @@ public final class SrgMerger {
if (tinyField != null) {
copyDstNames(dstNames, tinyField);
srcDesc = tinyField.getSrcDesc();
comment = tinyField.getComment();
} else {
fillMappings(dstNames, srgField);
}
if (srcDesc != null) {
flatOutput.visitField(srgClass.getSrcName(), srgField.getSrcName(), srcDesc, dstNames);
if (comment != null) flatOutput.visitFieldComment(srgClass.getSrcName(), srgField.getSrcName(), srcDesc, comment);
} else if (!lenient) {
throw new MappingException("Could not find descriptor for field " + srgClass.getDstName(0) + '.' + srgField.getDstName(0));
}
@@ -204,6 +210,7 @@ public final class SrgMerger {
String[] dstNames = createDstNameArray(srgMethod);
MappingTree.MethodMapping tinyMethod = null;
String intermediaryName, namedName;
String comment = null;
if (tinyClass != null) {
tinyMethod = tinyClass.getMethod(srgMethod.getSrcName(), srgMethod.getSrcDesc());
@@ -215,6 +222,7 @@ public final class SrgMerger {
copyDstNames(dstNames, tinyMethod);
intermediaryName = tinyMethod.getName("intermediary");
namedName = tinyMethod.getName("named");
comment = tinyMethod.getComment();
} else {
if (srgMethod.getSrcName().equals(srgMethod.getDstName(0))) {
// These are only methods like <init> or toString which have the same name in every NS.
@@ -251,6 +259,26 @@ public final class SrgMerger {
}
flatOutput.visitMethod(srgClass.getSrcName(), srgMethod.getSrcName(), srgMethod.getSrcDesc(), dstNames);
if (comment != null) flatOutput.visitMethodComment(srgClass.getSrcName(), srgMethod.getSrcName(), srgMethod.getSrcDesc(), comment);
if (tinyMethod != null) {
for (MappingTree.MethodArgMapping arg : tinyMethod.getArgs()) {
String[] argDstNames = new String[output.getDstNamespaces().size()];
copyDstNames(argDstNames, arg);
flatOutput.visitMethodArg(
srgClass.getSrcName(), srgMethod.getSrcName(), srgMethod.getSrcDesc(),
arg.getArgPosition(), arg.getLvIndex(), arg.getSrcName(), argDstNames
);
if (arg.getComment() != null) {
flatOutput.visitMethodArgComment(
srgClass.getSrcName(), srgMethod.getSrcName(), srgMethod.getSrcDesc(),
arg.getArgPosition(), arg.getLvIndex(), arg.getSrcName(),
arg.getComment()
);
}
}
}
}
/**
@@ -334,8 +362,9 @@ public final class SrgMerger {
* The SRG names will add a new namespace called {@code srg} so that the final namespaces
* are {@code official, srg, intermediary, named}.
*
* <p>This method does not care about method parameters, local variables or javadoc comments.
* As such, it shouldn't be used for remapping the game jar.
* <p>This method does not include local variables in the output.
* It can, however, be used for remapping the game jar since it has all
* classes, methods, fields, parameters and javadoc comments.
*
* <p>If {@code lenient} is true, the merger will not error when encountering names not present
* in the tiny mappings. Instead, the names will be filled from the {@code official} namespace.

View File

@@ -1,8 +1,14 @@
tiny 2 0 official srg intermediary named
c a test/FakeClass class_1 test/SomeClass
c commented class
f I a f_1_ field_1 myInt
c commented field
m ()I a m_1_ method_1 getMyInt
m ()V evilUnobfMethod m_3_ method_2 differentNamedName
m (I)V a m_5_ method_5 setMyInt
c commented method
p 1 myInt
c commented param
c b test/FakeSubclass class_2 test/SomeSubclass
c test/DeObfClass test/DeObfClass test/DeObfClass test/DeObfClass
m ()V iAmNotObfuscated m_2_ iAmNotObfuscated iAmNotObfuscated

View File

@@ -4,6 +4,7 @@ a test/FakeClass
a I fakeField
a ()I getFakeField
evilUnobfMethod ()V evilUnobfMethod
a (I)V setFakeField
b test/FakeSubclass
<init> ()V <init>
evilUnobfMethod ()V evilUnobfMethod

View File

@@ -3,6 +3,7 @@ test.FakeClass -> a:
int fakeField -> a
int getFakeField() -> a
void evilUnobfMethod() -> evilUnobfMethod
void setFakeField(int) -> a
test.FakeSubclass -> b:
void <init>() -> <init>
void evilUnobfMethod() -> evilUnobfMethod

View File

@@ -4,6 +4,7 @@ a test/FakeClass
a I f_1_
a ()I m_1_
evilUnobfMethod ()V m_3_
a (I)V m_5_
b test/FakeSubclass
<init> ()V <init>
a ()I m_1_

View File

@@ -1,8 +1,14 @@
tiny 2 0 official intermediary named
c a class_1 test/SomeClass
c commented class
f I a field_1 myInt
c commented field
m ()I a method_1 getMyInt
m ()V evilUnobfMethod method_2 differentNamedName
m (I)V a method_5 setMyInt
c commented method
p 1 myInt
c commented param
c b class_2 test/SomeSubclass
c c class_3 test/RelatedA
m ()V a method_3 fromClassA