Skip to content

Commit

Permalink
I might need to do this again.
Browse files Browse the repository at this point in the history
  • Loading branch information
BluSpring committed Jul 8, 2024
1 parent a32aa6b commit 0c20e10
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/net/minecraftforge/coremod/api/ASMAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ object ASMAPI {

@JvmStatic
fun mapMethod(name: String): String {
return KiltRemapper.srgMappedMethods[name]?.second ?: name
return KiltRemapper.srgMappedMethods[name]?.values?.firstOrNull() ?: name
}

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object ObfuscationReflectionHelper {
}

INameMappingService.Domain.METHOD -> {
srgMappedMethods[name]?.second ?: name
srgMappedMethods[name]?.values?.firstOrNull() ?: name
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/xyz/bluspring/kilt/loader/asm/CoreMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class CoreMod(val mod: ForgeMod, val id: String, val file: String) {
val methodName = targetData["methodName"] as String
val descName = targetData["methodDesc"] as String

val mappedMethodName = KiltRemapper.srgMappedMethods[methodName]?.second ?: methodName
val mappedMethodName = KiltRemapper.srgMappedMethods[methodName]?.get(className) ?: KiltRemapper.srgMappedMethods[methodName]?.values?.firstOrNull() ?: methodName
val mappedDescName = KiltRemapper.remapDescriptor(descName)

ClassTinkerers.addTransformation(KiltRemapper.remapClass(className, ignoreWorkaround = true)) { classNode ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ import java.util.function.Consumer
class KiltEnhancedRemapper(provider: ClassProvider, file: IMappingFile, log: Consumer<String>) : EnhancedRemapper(provider, file, log) {
override fun mapMethodName(owner: String, name: String, descriptor: String): String {
if (name.startsWith("m_") && name.endsWith("_")) {
return KiltRemapper.srgMappedMethods[name]?.second ?: super.mapMethodName(owner, name, descriptor)
return KiltRemapper.srgMappedMethods[name]?.get(owner) ?: KiltRemapper.srgMappedMethods[name]?.values?.firstOrNull() ?: super.mapMethodName(owner, name, descriptor)
}

return super.mapMethodName(owner, name, descriptor)
}

override fun mapInvokeDynamicMethodName(name: String, descriptor: String): String {
if (name.startsWith("m_") && name.endsWith("_")) {
return KiltRemapper.srgMappedMethods[name]?.values?.firstOrNull() ?: super.mapInvokeDynamicMethodName(name, descriptor)
}

return super.mapInvokeDynamicMethodName(name, descriptor)
}

override fun mapFieldName(owner: String, name: String, descriptor: String): String {
if (name.startsWith("f_") && name.endsWith("_")) {
return KiltRemapper.srgMappedFields[name]?.second ?: super.mapFieldName(owner, name, descriptor)
Expand Down
19 changes: 17 additions & 2 deletions src/main/kotlin/xyz/bluspring/kilt/loader/remap/KiltRemapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ object KiltRemapper {
// Keeps track of the remapper changes, so every time I update the remapper,
// it remaps all the mods following the remapper changes.
// this can update by like 12 versions in 1 update, so don't worry too much about it.
const val REMAPPER_VERSION = 122
const val REMAPPER_VERSION = 123

const val MC_MAPPED_JAR_VERSION = 2

Expand Down Expand Up @@ -92,7 +92,22 @@ object KiltRemapper {
private val classNodeList = mutableSetOf<ClassNode>()

val srgMappedFields = srgIntermediaryMapping.classes.flatMap { it.fields.map { f -> f.original to mappingResolver.mapFieldName("intermediary", it.mapped.replace("/", "."), f.mapped, f.mappedDescriptor) } }.associateBy { it.first }
val srgMappedMethods = srgIntermediaryMapping.classes.flatMap { it.methods.map { f -> f.original to mappingResolver.mapMethodName("intermediary", it.mapped.replace("/", "."), f.mapped, f.mappedDescriptor) } }.associateBy { it.first }
val srgMappedMethods = mutableMapOf<String, MutableMap<String, String>>()

init {
srgIntermediaryMapping.classes.forEach {
it.methods.forEach m@{ f ->
val map = srgMappedMethods.computeIfAbsent(f.original) { mutableMapOf() }
val mapped = (mappingResolver.mapMethodName("intermediary", it.mapped.replace("/", "."), f.mapped, f.mappedDescriptor))

// otherwise FunctionalInterface methods don't get remapped properly???
if (!mapped.startsWith("method_"))
return@m

map[f.parent.original] = mapped
}
}
}

fun remapMods(modLoadingQueue: ConcurrentLinkedQueue<ForgeMod>, remappedModsDir: File): List<Exception> {
if (disableRemaps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object MixinShadowRemapper {
if (method.visibleAnnotations.none { it.desc.contains("org/spongepowered/asm/mixin/Shadow") })
continue

val remapped = KiltRemapper.srgMappedMethods[method.name]?.second ?: continue
val remapped = KiltRemapper.srgMappedMethods[method.name]?.get(classNode.name.replace(".", "/")) ?: KiltRemapper.srgMappedMethods[method.name]?.values?.firstOrNull() ?: continue
remappedMethods[method.name] = remapped
method.name = remapped
}
Expand Down

0 comments on commit 0c20e10

Please sign in to comment.