add client/server jar merging
All checks were successful
Publish to snapshot maven / build (push) Successful in 55s

This commit is contained in:
moehreag 2024-09-30 23:17:22 +02:00
parent 64adbe82a5
commit 15987c805b
7 changed files with 174 additions and 53 deletions

View file

@ -7,7 +7,7 @@ plugins {
} }
group = "dev.frogmc" group = "dev.frogmc"
version = "0.0.1-alpha.25" + ("+local".takeUnless { project.hasProperty("FrogMCSnapshotsMavenPassword") } ?: "") version = "0.0.1-alpha.26" + ("+local".takeUnless { project.hasProperty("FrogMCSnapshotsMavenPassword") } ?: "")
repositories { repositories {
maven { maven {
@ -24,7 +24,7 @@ repositories {
} }
dependencies { dependencies {
implementation("dev.frogmc:thyroxine:0.0.1-alpha.16") implementation("dev.frogmc:thyroxine:0.0.1-alpha.17")
implementation("org.ow2.asm:asm:9.7") implementation("org.ow2.asm:asm:9.7")
implementation("org.ow2.asm:asm-commons:9.7") implementation("org.ow2.asm:asm-commons:9.7")
implementation("org.ow2.asm:asm-tree:9.7") implementation("org.ow2.asm:asm-tree:9.7")

View file

@ -1,6 +1,6 @@
#Sun May 12 17:35:40 BST 2024 #Sun May 12 17:35:40 BST 2024
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View file

@ -1,8 +1,6 @@
package dev.frogmc.phytotelma package dev.frogmc.phytotelma
import com.electronwill.nightconfig.core.CommentedConfig
import com.electronwill.nightconfig.core.file.FileNotFoundAction import com.electronwill.nightconfig.core.file.FileNotFoundAction
import com.electronwill.nightconfig.core.io.WritingMode
import com.electronwill.nightconfig.toml.TomlParser import com.electronwill.nightconfig.toml.TomlParser
import com.electronwill.nightconfig.toml.TomlWriter import com.electronwill.nightconfig.toml.TomlWriter
import dev.frogmc.phytotelma.accesswidener.AccessWidener import dev.frogmc.phytotelma.accesswidener.AccessWidener
@ -13,7 +11,6 @@ import dev.frogmc.phytotelma.ext.PhytotelmaGradleExtensionImpl
import dev.frogmc.phytotelma.mappings.renameDstNamespace import dev.frogmc.phytotelma.mappings.renameDstNamespace
import dev.frogmc.phytotelma.mixin.remapper.MixinAnnotationRemapper import dev.frogmc.phytotelma.mixin.remapper.MixinAnnotationRemapper
import dev.frogmc.phytotelma.nest.NestStripper import dev.frogmc.phytotelma.nest.NestStripper
import dev.frogmc.phytotelma.nest.Nester
import dev.frogmc.phytotelma.run.AssetDownloader import dev.frogmc.phytotelma.run.AssetDownloader
import dev.frogmc.phytotelma.run.RunConfigGenerator import dev.frogmc.phytotelma.run.RunConfigGenerator
import dev.frogmc.phytotelma.run.task.RunGameTask import dev.frogmc.phytotelma.run.task.RunGameTask
@ -31,6 +28,7 @@ import org.gradle.api.Project
import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.plugins.JavaPlugin import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.tasks.Delete import org.gradle.api.tasks.Delete
import org.gradle.internal.impldep.org.jsoup.helper.Consumer
import org.jetbrains.java.decompiler.main.Fernflower import org.jetbrains.java.decompiler.main.Fernflower
import org.jetbrains.java.decompiler.main.decompiler.PrintStreamLogger import org.jetbrains.java.decompiler.main.decompiler.PrintStreamLogger
import org.jetbrains.java.decompiler.main.decompiler.SingleFileSaver import org.jetbrains.java.decompiler.main.decompiler.SingleFileSaver
@ -40,10 +38,8 @@ import java.io.OutputStream
import java.io.PrintStream import java.io.PrintStream
import java.net.URI import java.net.URI
import java.nio.charset.StandardCharsets import java.nio.charset.StandardCharsets
import java.nio.file.FileSystems import java.nio.file.*
import java.nio.file.Files import java.nio.file.attribute.BasicFileAttributes
import java.nio.file.Path
import java.nio.file.StandardCopyOption
import java.time.LocalDateTime import java.time.LocalDateTime
import java.util.* import java.util.*
import kotlin.io.path.* import kotlin.io.path.*
@ -209,7 +205,8 @@ class PhytotelmaPlugin : Plugin<Project> {
val moj = if (storage.intermediaryNs == Constants.MOJMAP_NAMESPACE) { val moj = if (storage.intermediaryNs == Constants.MOJMAP_NAMESPACE) {
MojmapProvider.get( MojmapProvider.get(
storage.minecraftVersion!!, storage.minecraftVersion!!,
globalCacheDir.resolve("net/minecraft/client/${storage.minecraftVersion}/client-${storage.minecraftVersion}.txt") globalCacheDir.resolve("net/minecraft/client/${storage.minecraftVersion}/client-${storage.minecraftVersion}.txt"),
globalCacheDir.resolve("net/minecraft/server/${storage.minecraftVersion}/server-${storage.minecraftVersion}.txt")
).reverse().renameDstNamespace(Constants.MOJMAP_NAMESPACE) ).reverse().renameDstNamespace(Constants.MOJMAP_NAMESPACE)
} else null } else null
val mappings = (moj?.let { val mappings = (moj?.let {
@ -276,10 +273,10 @@ class PhytotelmaPlugin : Plugin<Project> {
} }
} }
private fun defaultRemappingSteps(sourceNsJar: Path): MutableList<RemappingStep> { private fun defaultRemappingSteps(vararg sourceNSJars: Path): MutableList<RemappingStep> {
return mutableListOf( return mutableListOf(
RemappingStep(::ClassRemapper), RemappingStep(::ClassRemapper),
RemappingStep { cv, mapper -> MixinAnnotationRemapper(cv, mapper, sourceNsJar) }, RemappingStep { cv, mapper -> MixinAnnotationRemapper(cv, mapper, *sourceNSJars) },
) )
} }
@ -289,7 +286,8 @@ class PhytotelmaPlugin : Plugin<Project> {
System.setOut(PrintStream(OutputStream.nullOutputStream())) System.setOut(PrintStream(OutputStream.nullOutputStream()))
val mojmapGameJar = ProjectStorage.get(project).remappedGameJarPath!!.resolveSibling("mojmap.jar") val mojmapGameJar = ProjectStorage.get(project).remappedGameJarPath!!.resolveSibling("mojmap.jar")
val version = ProjectStorage.get(project).minecraftVersion!! val version = ProjectStorage.get(project).minecraftVersion!!
val officialJar = VersionChecker.downloadClient(project, version) val officialClientJar = VersionChecker.downloadClient(project, version)
val officialServerJar = VersionChecker.downloadServer(project, version)
ModConfigurations.configurations.forEach { conf -> ModConfigurations.configurations.forEach { conf ->
val artifacts = project.configurations.getByName("mod" + conf.name.replaceFirstChar { val artifacts = project.configurations.getByName("mod" + conf.name.replaceFirstChar {
if (it.isLowerCase()) it.titlecase( if (it.isLowerCase()) it.titlecase(
@ -300,8 +298,32 @@ class PhytotelmaPlugin : Plugin<Project> {
if (artifacts.isEmpty()) { if (artifacts.isEmpty()) {
return return
} }
val mojmap = MojmapProvider.get(version,
globalCacheDir.resolve("net/minecraft/client/${version}/client-${version}.txt"),
globalCacheDir.resolve("net/minecraft/server/${version}/server-${version}.txt"))
if (mojmapGameJar.notExists()) { if (mojmapGameJar.notExists()) {
Thyroxine.run(version, officialJar, mojmapGameJar, true, false) val remappedClient = officialClientJar.resolveSibling("client-$version-mojmap.jar")
val remappedServer = officialServerJar.resolveSibling("server-$version-mojmap.jar")
Thyroxine.remap(mojmap.data.first(), officialClientJar, remappedClient, true, false)
Thyroxine.remap(mojmap.data.first(), officialServerJar, remappedServer, true, false)
FileSystems.newFileSystem(mojmapGameJar, mutableMapOf<String, String>("create" to "true")).use { mergedFs ->
val consumer = object : Consumer<FileSystem> {
override fun accept(fs: FileSystem) {
Files.walkFileTree(fs.getPath("/"), object : SimpleFileVisitor<Path>() {
override fun visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult {
val target = mergedFs.getPath(file.toString())
target.createParentDirectories()
if (target.notExists()) {
file.copyTo(target)
}
return super.visitFile(file, attrs)
}
})
}
}
FileSystems.newFileSystem(remappedClient).use { consumer.accept(it) }
FileSystems.newFileSystem(remappedServer).use { consumer.accept(it) }
}
} }
val target = project.configurations.create("mod" + conf.name.replaceFirstChar { val target = project.configurations.create("mod" + conf.name.replaceFirstChar {
if (it.isLowerCase()) it.titlecase( if (it.isLowerCase()) it.titlecase(
@ -323,10 +345,7 @@ class PhytotelmaPlugin : Plugin<Project> {
MappingBundle(officialStore), MappingBundle(officialStore),
project.projectDir.resolve("officialStore.tiny").toPath().writer() project.projectDir.resolve("officialStore.tiny").toPath().writer()
) )
val mojOfficial = MojmapProvider.get( val mojOfficial = mojmap.reverse().renameDstNamespace(Constants.MOJMAP_NAMESPACE).data[0].reverse()
storage.minecraftVersion!!,
globalCacheDir.resolve("net/minecraft/client/${storage.minecraftVersion}/client-${storage.minecraftVersion}.txt")
).reverse().renameDstNamespace(Constants.MOJMAP_NAMESPACE).data[0].reverse()
val targetPath = project.layout.buildDirectory.asFile.get().toPath().resolve("remappedMods") val targetPath = project.layout.buildDirectory.asFile.get().toPath().resolve("remappedMods")
.resolve("dev/frogmc/phytotelma/remapped_mods") .resolve("dev/frogmc/phytotelma/remapped_mods")
val remappedPaths = mutableListOf<Path>() val remappedPaths = mutableListOf<Path>()
@ -362,8 +381,8 @@ class PhytotelmaPlugin : Plugin<Project> {
) )
Thyroxine.remap( Thyroxine.remap(
officialStore, temp, remappedPath, false, defaultRemappingSteps( officialStore, temp, remappedPath, false, defaultRemappingSteps(
officialJar officialClientJar, officialServerJar
), officialJar ), officialClientJar, officialServerJar
) )
Files.deleteIfExists(temp) Files.deleteIfExists(temp)
NestStripper.stripJij(remappedPath) NestStripper.stripJij(remappedPath)

View file

@ -8,6 +8,7 @@ import com.google.gson.GsonBuilder
import dev.frogmc.phytotelma.common.CachingHttpClient import dev.frogmc.phytotelma.common.CachingHttpClient
import org.gradle.api.Project import org.gradle.api.Project
import java.net.URI import java.net.URI
import java.nio.file.FileSystems
import java.nio.file.Path import java.nio.file.Path
import kotlin.io.path.* import kotlin.io.path.*
@ -15,38 +16,85 @@ object VersionChecker {
private var validVersions = mutableListOf<VersionUrl>() private var validVersions = mutableListOf<VersionUrl>()
private var versionData: VersionData? = null private var versionData: VersionData? = null
@Suppress("DEPRECATION")
fun downloadServer(project: Project, version: String): Path {
fetchVersionData(project, version)
val versionData = fetchServerDownload(project, version)
val downloadDirectory = PhytotelmaPlugin.globalCacheDir.resolve("net/minecraft/server/$version/")
val bundleFile = downloadDirectory.resolve("server-$version-bundle.jar")
val downloadFile = downloadDirectory.resolve("server-$version.jar")
if (!project.gradle.startParameter.isRefreshDependencies && bundleFile.exists()) {
if (versionData.sha1 == Hashing.sha1().hashBytes(bundleFile.readBytes()).toString()) {
if (downloadFile.exists()) {
FileSystems.newFileSystem(bundleFile).use { fs ->
val hash = fs.getPath("/META-INF/versions.list").readText().split("\t")[0]
if (hash == Hashing.sha256().hashBytes(downloadFile.readBytes()).toString()) {
return downloadFile
}
}
}
}
}
println("Downloading server...")
downloadDirectory.createDirectories()
val raw = rawDownload(versionData.url)
bundleFile.writeBytes(raw)
FileSystems.newFileSystem(bundleFile).use { fs ->
val metaInf = fs.getPath("/META-INF")
val versionsList = metaInf.resolve("versions.list").readText()
val jar = metaInf.resolve("versions").resolve(versionsList.split("\t")[2])
jar.copyTo(downloadFile)
}
return downloadFile
}
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
fun downloadClient(project: Project, version: String): Path { fun downloadClient(project: Project, version: String): Path {
fetchVersionData(project, version) fetchVersionData(project, version)
val clientData = fetchClientDownload(project, version) val versionData = fetchClientDownload(project, version)
// download client data // download client data
val downloadDirectory = PhytotelmaPlugin.globalCacheDir.resolve("net/minecraft/client/$version/") val downloadDirectory = PhytotelmaPlugin.globalCacheDir.resolve("net/minecraft/client/$version/")
val downloadFile = downloadDirectory.resolve("client-$version.jar") val downloadFile = downloadDirectory.resolve("client-$version.jar")
if (!project.gradle.startParameter.isRefreshDependencies && downloadFile.exists()) { if (!project.gradle.startParameter.isRefreshDependencies && downloadFile.exists()) {
if (clientData.sha1 == Hashing.sha1().hashBytes(downloadFile.readBytes()).toString()) { if (versionData.sha1 == Hashing.sha1().hashBytes(downloadFile.readBytes()).toString()) {
return downloadFile return downloadFile
} }
} }
println("Downloading client...") println("Downloading client...")
downloadDirectory.createDirectories() downloadDirectory.createDirectories()
val raw = rawDownload(clientData.url) val raw = rawDownload(versionData.url)
downloadFile.writeBytes(raw) downloadFile.writeBytes(raw)
return downloadFile return downloadFile
} }
fun savePomFile(version: String, dir: Path) { fun saveClientPomFile(version: String, dir: Path) {
savePomFile(version, dir, "client")
}
fun saveServerPomFile(version: String, dir: Path) {
savePomFile(version, dir, "server")
}
fun saveMergedPomFile(version: String, dir: Path) {
savePomFile(version, dir, "minecraft-merged")
}
private fun savePomFile(version: String, dir: Path, name: String) {
val content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + val content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<project xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\" xmlns=\"http://maven.apache.org/POM/4.0.0\"\n" + "<project xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\" xmlns=\"http://maven.apache.org/POM/4.0.0\"\n" +
"\t\t xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" + "\t\t xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
"\t<modelVersion>4.0.0</modelVersion>\n" + "\t<modelVersion>4.0.0</modelVersion>\n" +
"\t<groupId>net.minecraft</groupId>\n" + "\t<groupId>net.minecraft</groupId>\n" +
"\t<artifactId>client</artifactId>\n" + "\t<artifactId>$name</artifactId>\n" +
"\t<version>$version</version>\n" + "\t<version>$version</version>\n" +
"</project>" "</project>"
dir.resolve("client-$version.pom").writeText(content) dir.resolve("$name-$version.pom").writeText(content)
} }
fun getDependencies(project: Project, version: String, action: (String) -> Unit) { fun getDependencies(project: Project, version: String, action: (String) -> Unit) {
fetchVersionData(project, version).libraries.map { it.name }.forEach { fetchVersionData(project, version).libraries.map { it.name }.forEach {
action.invoke(it) action.invoke(it)
@ -78,10 +126,14 @@ object VersionChecker {
return versionData!! return versionData!!
} }
fun fetchClientDownload(project: Project, version: String): VersionClientData { private fun fetchClientDownload(project: Project, version: String): VersionDownloadData {
return fetchVersionData(project, version).downloads.client return fetchVersionData(project, version).downloads.client
} }
private fun fetchServerDownload(project: Project, version: String): VersionDownloadData {
return fetchVersionData(project, version).downloads.server
}
private fun rawDownload(url: String): ByteArray { private fun rawDownload(url: String): ByteArray {
return CachingHttpClient.getUncached(URI.create(url)).readAllBytes() return CachingHttpClient.getUncached(URI.create(url)).readAllBytes()
} }
@ -133,6 +185,6 @@ class LibraryDownload(val artifact: LibraryArtifact, val name: String)
class LibraryArtifact(val path: String, val sha1: String, val size: Int, val url: String) class LibraryArtifact(val path: String, val sha1: String, val size: Int, val url: String)
class AssetIndex(val id: String, val sha1: String, val size: Int, val totalSize: Int, val url: String) class AssetIndex(val id: String, val sha1: String, val size: Int, val totalSize: Int, val url: String)
class VersionDownloads(val client: VersionClientData) class VersionDownloads(val client: VersionDownloadData, val server: VersionDownloadData)
class VersionClientData(val sha1: String, val size: Int, val url: String) class VersionDownloadData(val sha1: String, val size: Int, val url: String)

View file

@ -52,7 +52,8 @@ abstract class MinecraftConfiguration @Inject constructor(
return@provider MappingBundle.merge( return@provider MappingBundle.merge(
MojmapProvider.get( MojmapProvider.get(
version.get(), version.get(),
cacheDir.resolve("net/minecraft/client/${version.get()}/client-${version.get()}.txt") cacheDir.resolve("net/minecraft/client/${version.get()}/client-${version.get()}.txt"),
cacheDir.resolve("net/minecraft/server/${version.get()}/server-${version.get()}.txt")
).reverse(), ).reverse(),
ParchmentProvider.getParchment( ParchmentProvider.getParchment(
conf.gameVersion.get(), conf.gameVersion.get(),
@ -87,7 +88,8 @@ abstract class MinecraftConfiguration @Inject constructor(
targetNamespace = Constants.MOJMAP_NAMESPACE targetNamespace = Constants.MOJMAP_NAMESPACE
return@provider MojmapProvider.get( return@provider MojmapProvider.get(
version.get(), version.get(),
cacheDir.resolve("net/minecraft/client/${version.get()}/client-${version.get()}.txt") cacheDir.resolve("net/minecraft/client/${version.get()}/client-${version.get()}.txt"),
cacheDir.resolve("net/minecraft/server/${version.get()}/server-${version.get()}.txt")
).reverse().renameDstNamespace(targetNamespace) ).reverse().renameDstNamespace(targetNamespace)
} }
} }

View file

@ -17,8 +17,11 @@ import org.gradle.api.Action
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.model.ObjectFactory import org.gradle.api.model.ObjectFactory
import org.gradle.api.plugins.JavaPlugin import org.gradle.api.plugins.JavaPlugin
import java.nio.file.Files import org.gradle.internal.impldep.org.jsoup.helper.Consumer
import java.nio.file.*
import java.nio.file.attribute.BasicFileAttributes
import javax.inject.Inject import javax.inject.Inject
import kotlin.io.path.copyTo
import kotlin.io.path.createParentDirectories import kotlin.io.path.createParentDirectories
import kotlin.io.path.notExists import kotlin.io.path.notExists
@ -46,21 +49,61 @@ abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
projectData.mappings = mappings projectData.mappings = mappings
val clientJar = VersionChecker.downloadClient(project, version) val clientJar = VersionChecker.downloadClient(project, version)
val remappedJar = val serverJar = VersionChecker.downloadServer(project, version)
val remappedClientJar =
projectData.localCacheDir!!.resolve("net/minecraft/client/$version/client-$version-remapped.jar") projectData.localCacheDir!!.resolve("net/minecraft/client/$version/client-$version-remapped.jar")
remappedJar.createParentDirectories() val remappedServerJar =
projectData.remappedGameJarPath = remappedJar projectData.localCacheDir!!.resolve("net/minecraft/server/$version/server-$version-remapped.jar")
var applyAW = AccessWidener.needsUpdate(project) remappedClientJar.createParentDirectories()
projectData.intermediaryNs = mcConf.intermediaryNamespace.get() remappedServerJar.createParentDirectories()
if (remappedJar.notExists() || applyAW || mcConf.mappingsName != projectData.mappingsName) { if (remappedClientJar.notExists() || mcConf.mappingsName != projectData.mappingsName) {
projectData.mappingsName = mcConf.mappingsName println("Remapping client...")
println("Remapping the game...")
projectData.targetNamespace = mcConf.targetNamespace
Thyroxine.remap( Thyroxine.remap(
mappings.forNamespaces("official", mcConf.targetNamespace), mappings.forNamespaces("official", mcConf.targetNamespace),
clientJar, remappedJar, true, true clientJar, remappedClientJar, true, true
) )
VersionChecker.savePomFile(version, remappedJar.parent) VersionChecker.saveClientPomFile(version, remappedClientJar.parent)
}
if (remappedServerJar.notExists() || mcConf.mappingsName != projectData.mappingsName) {
println("Remapping server...")
Thyroxine.remap(
mappings.forNamespaces("official", mcConf.targetNamespace),
serverJar, remappedServerJar, true, true
)
VersionChecker.saveServerPomFile(version, remappedServerJar.parent)
}
val mergedJar =
projectData.localCacheDir!!.resolve("net/minecraft/minecraft-merged/$version/minecraft-merged-$version.jar")
projectData.remappedGameJarPath = mergedJar
var applyAW = AccessWidener.needsUpdate(project)
projectData.intermediaryNs = mcConf.intermediaryNamespace.get()
if (mergedJar.notExists() || applyAW || mcConf.mappingsName != projectData.mappingsName) {
projectData.mappingsName = mcConf.mappingsName
println("Merging game...")
FileSystems.newFileSystem(mergedJar, mutableMapOf<String, String>("create" to "true")).use { mergedFs ->
val consumer = object : Consumer<FileSystem> {
override fun accept(fs: FileSystem) {
Files.walkFileTree(fs.getPath("/"), object : SimpleFileVisitor<Path>() {
override fun visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult {
val target = mergedFs.getPath(file.toString())
target.createParentDirectories()
if (target.notExists()) {
file.copyTo(target)
}
return super.visitFile(file, attrs)
}
})
}
}
FileSystems.newFileSystem(remappedClientJar).use { consumer.accept(it) }
FileSystems.newFileSystem(remappedServerJar).use { consumer.accept(it) }
}
projectData.targetNamespace = mcConf.targetNamespace
RunConfigGenerator.generate(project) RunConfigGenerator.generate(project)
applyAW = AccessWidener.hasAW(project) applyAW = AccessWidener.hasAW(project)
} }
@ -77,29 +120,29 @@ abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
VersionChecker.getDependencies(project, version) { VersionChecker.getDependencies(project, version) {
project.dependencies.add(Constants.MINECRAFT_CONFIGURATION, it) project.dependencies.add(Constants.MINECRAFT_CONFIGURATION, it)
} }
project.dependencies.add(Constants.MINECRAFT_CONFIGURATION, "net.minecraft:client:$version:remapped") project.dependencies.add(Constants.MINECRAFT_CONFIGURATION, "net.minecraft:minecraft-merged:$version")
AssetDownloader.download(project) AssetDownloader.download(project)
if (applyAW) { if (applyAW) {
project.afterEvaluate { project.afterEvaluate {
println("Applying AccessWideners...") println("Applying AccessWideners...")
AccessWidener.apply(project, remappedJar) AccessWidener.apply(project, mergedJar)
} }
} }
project.afterEvaluate { project.afterEvaluate {
if (mcConf.targetNamespace != Constants.MOJMAP_NAMESPACE) { if (mcConf.targetNamespace != Constants.MOJMAP_NAMESPACE) {
Thyroxine.remap( Thyroxine.remap(
MappingData("", ""), MappingData("", ""),
remappedJar, mergedJar,
remappedJar.resolveSibling(Constants.ALTERNATIVE_RUNTIME_JAR_NAME), mergedJar.resolveSibling(Constants.ALTERNATIVE_RUNTIME_JAR_NAME),
false, false,
listOf(RemappingStep { classVisitor, _ -> listOf(RemappingStep { classVisitor, _ ->
RuntimeAccessFixVisitor(classVisitor) RuntimeAccessFixVisitor(classVisitor)
}) })
) )
} else { } else {
Files.deleteIfExists(remappedJar.resolveSibling(Constants.ALTERNATIVE_RUNTIME_JAR_NAME)) Files.deleteIfExists(mergedJar.resolveSibling(Constants.ALTERNATIVE_RUNTIME_JAR_NAME))
} }
} }
} }

View file

@ -17,7 +17,7 @@ import kotlin.io.path.readBytes
class MixinAnnotationRemapper( class MixinAnnotationRemapper(
cv: ClassVisitor, cv: ClassVisitor,
private val mapper: Remapper, private val mapper: Remapper,
private val mojmapGameJar: Path private vararg val contextJars: Path
) : ClassRemapper(Constants.ASM_VERSION, cv, mapper) { ) : ClassRemapper(Constants.ASM_VERSION, cv, mapper) {
private var target: String? = null private var target: String? = null
@ -80,9 +80,14 @@ class MixinAnnotationRemapper(
override fun visitEnd() { override fun visitEnd() {
if (target != null) { if (target != null) {
targetNode = ClassNode() targetNode = ClassNode()
FileSystems.newFileSystem(mojmapGameJar).use { fs -> for (gameJar in contextJars) {
fs.getPath("$target.class").takeIf { it.exists() } FileSystems.newFileSystem(gameJar).use { fs ->
?.readBytes()?.let(::ClassReader).let { it?.accept(targetNode, 0) } fs.getPath("$target.class").takeIf { it.exists() }
?.readBytes()?.let(::ClassReader).let { it?.accept(targetNode, 0) }
}
if (targetNode != null) {
break
}
} }
} }
super.visitEnd() super.visitEnd()