Skip to content

Commit

Permalink
obfuscate impl entrypoints and simplify fmj remapping
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysdh540 committed Jun 1, 2024
1 parent c7447e3 commit 9cae9dd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 28 deletions.
27 changes: 1 addition & 26 deletions buildSrc/src/main/kotlin/dev/nolij/zumegradle/JarCompressing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ fun squishJar(jar: File, classProcessing: ClassShrinkingType, jsonProcessing: Js

JarOutputStream(jar.outputStream()).use { out ->
out.setLevel(Deflater.BEST_COMPRESSION)
contents.forEach {
var (name, bytes) = it
if (name == "fabric.mod.json" && isObfuscating) {
bytes = remapFMJ(bytes, mappings!!)
}
contents.forEach { var (name, bytes) = it

if (name.endsWith("mixins.json") && isObfuscating) {
bytes = remapMixinConfig(bytes, mappings!!)
Expand Down Expand Up @@ -108,27 +104,6 @@ fun squishJar(jar: File, classProcessing: ClassShrinkingType, jsonProcessing: Js
}
}

@Suppress("UNCHECKED_CAST")
private fun remapFMJ(bytes: ByteArray, mappings: MemoryMappingTree): ByteArray {
val json = (JsonSlurper().parse(bytes) as Map<String, Any>).toMutableMap()
var entrypoints = (json["entrypoints"] as Map<String, List<String>>?)?.toMutableMap()
if (entrypoints == null) {
throw IllegalStateException("fabric.mod.json does not contain entrypoints")
}

val newEntrypoints = mutableMapOf<String, MutableList<String>>()
for ((type, classes) in entrypoints) {
for (old in classes) {
val obf = mappings.obfuscate(old)
newEntrypoints.computeIfAbsent(type) { mutableListOf() }.add(obf)
}
}

json["entrypoints"] = newEntrypoints

return JsonOutput.toJson(json).toByteArray()
}

@Suppress("UNCHECKED_CAST")
private fun remapMixinConfig(bytes: ByteArray, mappings: MemoryMappingTree): ByteArray {
val json = (JsonSlurper().parse(bytes) as Map<String, Any>).toMutableMap()
Expand Down
5 changes: 3 additions & 2 deletions proguard.pro
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
@*.*.fml.common.Mod$EventHandler <methods>;
@*.*.fml.common.eventhandler.SubscribeEvent <methods>;
}
# preserve class name but allow member obfuscation
-keep class dev.nolij.zume.** implements dev.nolij.zume.api.platform.v*.IZumeImplementation {}

-adaptclassstrings
-adaptresourcefilecontents fabric.mod.json

# screens
-keepclassmembers class dev.nolij.zume.** extends net.minecraft.class_437,
Expand Down

0 comments on commit 9cae9dd

Please sign in to comment.