Skip to content

Commit

Permalink
Fix a few things
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed Jan 5, 2024
1 parent 0fd77d7 commit 1625868
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ internal class PsiMapper(

// val ambiguousName = mapping.methodMappings.count { it.deobfuscatedName == mappedName } > 1
val ambiguousName = targetMethod?.containingClass?.methods?.moreThan(1) {
!it.isConstructor && findMapping(it)?.deobfuscatedName == mappedName
!it.isConstructor && (findMapping(it)?.deobfuscatedName ?: it.name) == mappedName
} ?: false
val mapped = mappedName + when {
ambiguousName && targetMethod != null ->
Expand All @@ -550,10 +550,12 @@ internal class PsiMapper(
private fun remapInternalType(internalType: String, result: StringBuilder): ClassMapping<*, *>? {
var dimensionCount = 0
while (internalType[dimensionCount] == '[') {
result.append('[')
dimensionCount++
}
if (internalType[dimensionCount] == 'L') {
if (dimensionCount > 0) {
result.append(internalType, 0, dimensionCount)
}
val type = internalType.substring(dimensionCount + 1, internalType.length - 1).replace('/', '.')
val mapping = map.findClassMapping(type)
if (mapping != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,33 @@ class TestMixinInjections {
}
""".trimIndent()
}

@Test
fun `remaps injections that use @At INVOKE with an unmapped array type in the descriptor`() {
TestData.remap("""
@org.spongepowered.asm.mixin.Mixin(a.pkg.A.class)
class MixinA {
@org.spongepowered.asm.mixin.injection.Inject(
method = "aCallArrayMethod",
at = @org.spongepowered.asm.mixin.injection.At(
value = "INVOKE",
target = "La/pkg/A;aArrayMethod()[B"
)
)
private void test() {}
}
""".trimIndent()) shouldBe """
@org.spongepowered.asm.mixin.Mixin(b.pkg.B.class)
class MixinA {
@org.spongepowered.asm.mixin.injection.Inject(
method = "bCallArrayMethod",
at = @org.spongepowered.asm.mixin.injection.At(
value = "INVOKE",
target = "Lb/pkg/B;bArrayMethod()[B"
)
)
private void test() {}
}
""".trimIndent()
}
}
2 changes: 2 additions & 0 deletions src/test/resources/mappings.srg
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ MD: a/pkg/A/commonOverloaded (Ljava/lang/Object;)V b/pkg/B/commonOverloaded (Lja
MD: a/pkg/A/commonOverloaded (La/pkg/A;)V b/pkg/B/commonOverloaded (La/pkg/B;)V
MD: a/pkg/A/aLambdaWithGeneric (Ljava/util/function/Supplier;)V b/pkg/B/bLambdaWithGeneric (Ljava/util/function/Supplier;)V
MD: a/pkg/A/lambda$aLambdaWithGeneric$0 (Ljava/util/function/Supplier;)Ljava/lang/String; b/pkg/B/lambda$bLambdaWithGeneric$0 (Ljava/util/function/Supplier;)Ljava/lang/String;
MD: a/pkg/A/aArrayMethod ()[B b/pkg/B/bArrayMethod ()[B
MD: a/pkg/A/aCallArrayMethod ()V b/pkg/B/bCallArrayMethod ()V
CL: a/pkg/A$1 b/pkg/B$1
CL: a/pkg/A$2 b/pkg/B$2
MD: a/pkg/A$2/aMethodAnon ()V b/pkg/B$2/bMethodAnon ()V
Expand Down
8 changes: 8 additions & 0 deletions src/testA/java/a/pkg/A.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ public void aLambdaWithGeneric(Supplier<String> supplier) {
final Supplier<String> prefixed = () -> "Hi, " + supplier.get();
}

public byte[] aArrayMethod() {
return new byte[0];
}

public void aCallArrayMethod() {
final byte[] value = aArrayMethod();
}

public void aAnon() {
new A() {
public void aMethodAnon() {
Expand Down
8 changes: 8 additions & 0 deletions src/testB/java/b/pkg/B.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ public void bLambdaWithGeneric(Supplier<String> supplier) {
final Supplier<String> prefixed = () -> "Hi, " + supplier.get();
}

public byte[] bArrayMethod() {
return new byte[0];
}

public void bCallArrayMethod() {
final byte[] value = bArrayMethod();
}

public void bAnon() {
new B() {
public void bMethodAnon() {
Expand Down

0 comments on commit 1625868

Please sign in to comment.