-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add conflicting PL method fixer and fix mixin refmap remapping withou…
…t owner classes
- Loading branch information
Showing
3 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
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
48 changes: 48 additions & 0 deletions
48
src/main/kotlin/xyz/bluspring/kilt/loader/remap/fixers/ConflictingStaticMethodFixer.kt
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package xyz.bluspring.kilt.loader.remap.fixers | ||
|
||
import net.fabricmc.loader.api.FabricLoader | ||
import org.objectweb.asm.Opcodes | ||
import org.objectweb.asm.tree.AbstractInsnNode | ||
import org.objectweb.asm.tree.ClassNode | ||
import org.objectweb.asm.tree.MethodInsnNode | ||
import xyz.bluspring.kilt.loader.remap.KiltRemapper | ||
|
||
// Porting Lib makes some methods virtual instead of static. | ||
// Let's remap the methods that conflict with Porting Lib. | ||
object ConflictingStaticMethodFixer { | ||
private val mappingResolver = FabricLoader.getInstance().mappingResolver | ||
|
||
private val conflictingMethods = mapOf( | ||
mappingResolver.mapClassName("intermediary", "net.minecraft.class_3499").replace(".", "/") to listOf( | ||
"transformedVec3d" to KiltRemapper.remapDescriptor("(Lnet/minecraft/class_3492;Lnet/minecraft/class_243;)Lnet/minecraft/class_243;"), | ||
"processEntityInfos" to KiltRemapper.remapDescriptor("(Lnet/minecraft/class_3499;Lnet/minecraft/class_1936;Lnet/minecraft/class_2338;Lnet/minecraft/class_3492;Ljava/util/List;)Ljava/util/List;") | ||
) | ||
) | ||
|
||
fun fixClass(classNode: ClassNode) { | ||
for (method in classNode.methods) { | ||
val newNodeMap = mutableMapOf<AbstractInsnNode, AbstractInsnNode>() | ||
|
||
for (insnNode in method.instructions) { | ||
// Target static invokes specifically | ||
if (insnNode is MethodInsnNode && insnNode.opcode == Opcodes.INVOKESTATIC) { | ||
val specificClass = conflictingMethods.keys.firstOrNull { it == insnNode.owner } ?: continue | ||
val methodList = conflictingMethods[specificClass]!! | ||
|
||
if (methodList.none { it.first == insnNode.name && it.second == insnNode.desc }) | ||
continue | ||
|
||
// prefix with Forge | ||
val node = MethodInsnNode(insnNode.opcode, insnNode.owner, "forge\$${insnNode.name}", insnNode.desc) | ||
newNodeMap[insnNode] = node | ||
} | ||
} | ||
|
||
if (newNodeMap.isNotEmpty()) { | ||
for ((oldNode, newNode) in newNodeMap) { | ||
method.instructions.set(oldNode, newNode) | ||
} | ||
} | ||
} | ||
} | ||
} |