LibsDisguises/nms/specialSource.gradle

92 lines
4.0 KiB
Groovy
Raw Normal View History

2024-08-05 13:12:51 +02:00
// Code copied from https://github.com/Shopkeepers/Shopkeepers/tree/master
buildscript {
repositories {
mavenCentral()
}
configurations.create('specialSource')
dependencies {
specialSource 'net.md-5:SpecialSource:1.11.4:shaded'
}
}
// Spigot server code remapping: https://www.spigotmc.org/threads/spigot-bungeecord-1-17-1-17-1.510208/
// These dependencies and mappings are installed into the local Maven repository when BuildTools builds the Spigot dependencies.
2024-11-12 07:37:25 +01:00
def gradleCache = new File(System.getProperty("user.home"), '.gradle/caches/modules-2/files-2.1')
def findInGradleCache = { group, module, version, fileName ->
def baseDir = new File(gradleCache, "${group}/${module}/${version}")
if (!baseDir.exists()) {
throw new Exception("Failed to resolve ${baseDir} when trying to load ${fileName}. Cache missing");
}
def result = baseDir.listFiles()?.findAll { it.isDirectory() }?.collectMany({ it.listFiles().flatten() })?.find { it.name == fileName }?.path
if (result == null) {
throw new Exception("Failed to resolve ${baseDir}/<cache key>/${fileName}");
}
return result;
}
2024-08-05 13:12:51 +02:00
def specialSource = buildscript.configurations.specialSource.resolvedConfiguration.getFirstLevelModuleDependencies().find {
it.moduleGroup == 'net.md-5' && it.moduleName == 'SpecialSource'
}.moduleArtifacts.first().file.path
// Converts from Mojang's mappings to Minecraft's obfuscated mappings.
ext.remapMojangToObfuscated = { inputFile, outputFile, craftbukkitVersion ->
2024-11-12 07:37:25 +01:00
def remappedMojang = findInGradleCache("org.spigotmc", "spigot", craftbukkitVersion, "spigot-${craftbukkitVersion}-remapped-mojang.jar")
def mojangMappings = findInGradleCache("org.spigotmc", "minecraft-server", craftbukkitVersion, "minecraft-server-${craftbukkitVersion}-maps-mojang.txt")
2024-08-05 13:12:51 +02:00
println '> remapMojangToObfuscated'
println ' Input: ' + inputFile.path
println ' Output: ' + outputFile.path
println ' CraftBukkit version: ' + craftbukkitVersion
def classpathSeparator = System.properties['path.separator']
exec {
commandLine 'java',
'-cp', "${specialSource}${classpathSeparator}${remappedMojang}".replace('{craftbukkitVersion}', craftbukkitVersion),
'net.md_5.specialsource.SpecialSource',
'--live',
'-i', inputFile.path,
'-o', outputFile.path,
2024-11-12 07:37:25 +01:00
'-m', mojangMappings,
2024-08-05 13:12:51 +02:00
'--reverse'
}
}
// Converts from Minecraft's obfuscated mappings to Spigot's mappings.
ext.remapObfuscatedToSpigot = { inputFile, outputFile, craftbukkitVersion ->
2024-11-12 07:37:25 +01:00
def spigotMappings = findInGradleCache("org.spigotmc", "minecraft-server", craftbukkitVersion, "minecraft-server-${craftbukkitVersion}-maps-spigot.csrg")
def remappedObf = findInGradleCache("org.spigotmc", "spigot", craftbukkitVersion, "spigot-${craftbukkitVersion}-remapped-obf.jar")
2024-08-05 13:12:51 +02:00
println '> remapObfuscatedToSpigot'
println ' Input: ' + inputFile.path
println ' Output: ' + outputFile.path
println ' CraftBukkit version: ' + craftbukkitVersion
def classpathSeparator = System.properties['path.separator']
exec {
commandLine 'java',
'-cp', "${specialSource}${classpathSeparator}${remappedObf}".replace('{craftbukkitVersion}', craftbukkitVersion),
'net.md_5.specialsource.SpecialSource',
'--live',
'-i', inputFile.path,
'-o', outputFile.path,
2024-11-12 07:37:25 +01:00
'-m', spigotMappings
2024-08-05 13:12:51 +02:00
}
}
// Converts from Mojang's mappings to Spigot's mappings.
ext.remapMojangToSpigot = { inputFile, intermediateFile, outputFile, craftbukkitVersion ->
println '> remapMojangToSpigot'
println ' Input: ' + inputFile.path
println ' Intermediate: ' + intermediateFile.path
println ' Output: ' + outputFile.path
println ' CraftBukkit version: ' + craftbukkitVersion
remapMojangToObfuscated(inputFile, intermediateFile, craftbukkitVersion)
remapObfuscatedToSpigot(intermediateFile, outputFile, craftbukkitVersion)
}