Skip to content

Commit

Permalink
Update for mc 1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz committed Dec 1, 2021
1 parent 0a4422c commit e3648a7
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 91 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'io.izzel.arclight'
version '1.20'
version '1.21'

repositories {
mavenCentral()
Expand All @@ -25,8 +25,8 @@ dependencies {
implementation group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true
embed group: 'net.md-5', name: 'SpecialSource', version: '1.10.0'
implementation "org.cadixdev:mercury:0.1.0"
embed 'org.cadixdev:lorenz-io-proguard:0.5.7'
embed 'org.cadixdev:lorenz:0.5.7'
embed 'org.cadixdev:lorenz-io-proguard:0.5.8'
embed 'org.cadixdev:lorenz:0.5.8'
}

java.toolchain.languageVersion = JavaLanguageVersion.of(16)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ArclightGradlePlugin implements Plugin<Project> {
def processMapping = project.tasks.create('processMapping', ProcessMappingV2Task)
def remapSpigot = project.tasks.create('remapSpigotJar', RemapSpigotTask)
def generateMeta = project.tasks.create('generateArclightMeta', Copy)
def processAt = project.tasks.create('processAT', ProcessAccessTransformerTask)
//def processAt = project.tasks.create('processAT', ProcessAccessTransformerTask)
def downloadInstaller = project.tasks.create('downloadInstaller')
generateMeta.dependsOn(downloadInstaller)
def metaFolder = project.file("${project.buildDir}/arclight_cache/meta")
Expand All @@ -94,13 +94,13 @@ class ArclightGradlePlugin implements Plugin<Project> {
task.packageName = arclightExt.packageName
task.dependsOn(extractSrg, createSrgToMcp, buildSpigot)
}
processAt.configure { ProcessAccessTransformerTask task ->
task.buildData = new File(buildTools, 'BuildData')
task.mcVersion = arclightExt.mcVersion
task.outDir = project.file("${project.buildDir}/arclight_cache/tmp_srg")
task.inSrg = extractSrg.output.get().asFile
task.dependsOn(extractSrg, createSrgToMcp, buildSpigot)
}
//processAt.configure { ProcessAccessTransformerTask task ->
// task.buildData = new File(buildTools, 'BuildData')
// task.mcVersion = arclightExt.mcVersion
// task.outDir = project.file("${project.buildDir}/arclight_cache/tmp_srg")
// task.inSrg = extractSrg.output.get().asFile
// task.dependsOn(extractSrg, createSrgToMcp, buildSpigot)
//}
remapSpigot.configure { RemapSpigotTask task ->
task.ssJar = new File(buildTools, 'BuildData/bin/SpecialSource.jar')
task.inJar = new File(buildTools, "spigot-${arclightExt.mcVersion}.jar")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction

import javax.inject.Inject
import java.util.jar.JarFile

class BuildSpigotTask extends DefaultTask {

Expand Down Expand Up @@ -73,5 +74,16 @@ class BuildSpigotTask extends DefaultTask {
]
standardOutput = System.out
}
def bundler = new File(outSpigot.parentFile, 'bundler-' + outSpigot.name)
outSpigot.renameTo(bundler)
new JarFile(bundler).with {
it.stream().filter(ent -> ent.name.startsWith('META-INF/versions/') && ent.name.endsWith('.jar'))
.limit(1)
.forEach { ent ->
outSpigot.withOutputStream { out ->
it.getInputStream(ent).transferTo(out)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,14 @@ import org.cadixdev.lorenz.io.srg.csrg.CSrgReader
import org.cadixdev.lorenz.io.srg.tsrg.TSrgReader
import org.cadixdev.lorenz.io.srg.tsrg.TSrgWriter
import org.cadixdev.lorenz.model.ClassMapping
import org.cadixdev.lorenz.model.MethodMapping
import org.cadixdev.lorenz.model.TopLevelClassMapping
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.*
import org.objectweb.asm.commons.Remapper

import java.util.stream.Collectors

class ProcessMappingV2Task extends DefaultTask {

private static final def PKG = [
'it', 'org/apache', 'jline', 'org/codehaus', 'org/eclipse'
]
private static final Map<String, String> KNOWN_WRONG_MAP = ['m_7870_': 'startDrownedConversion']

private File buildData
private File inSrg
private File inMcp
Expand All @@ -42,10 +35,6 @@ class ProcessMappingV2Task extends DefaultTask {
clFile.withReader {
new CSrgReader(it).read(csrg)
}
def memberFile = new File(buildData, "mappings/bukkit-$mcVersion-members.csrg")
memberFile.withReader {
csrg = csrg.merge(new CSrgReader(it).read())
}
def srg = MappingSet.create()
inSrg.withReader {
def data = it.lines().filter { String s -> !(s.startsWith('\t\t') || s.startsWith('tsrg2')) }.collect(Collectors.joining('\n'))
Expand Down Expand Up @@ -73,78 +62,14 @@ class ProcessMappingV2Task extends DefaultTask {
}
def srgRev = srg.reverse()
def finalMap = srgRev.merge(csrg).reverse()
Map<String, String> seenNames = [:]
finalMap.topLevelClassMappings.each {
if (!it.fullObfuscatedName.contains('/')) {
return
}
it.methodMappings.each { MethodMapping m ->
if (!m.hasDeobfuscatedName()) {
return
}
def s = m.deobfuscatedName
if (!s.startsWith('m_')) {
def c = srgRev.getTopLevelClassMapping(m.parent.deobfuscatedName).get()
if (c.getMethodMapping(m.deobfuscatedSignature).isEmpty()) {
if (m.obfuscatedName.length() > 4) {
def candidate = it.methodMappings.find { t -> t.obfuscatedName == m.obfuscatedName && t.deobfuscatedName != m.deobfuscatedName }
if (candidate) {
m.deobfuscatedName = candidate.deobfuscatedName
}
}
if (s == m.deobfuscatedName) {
println('No mapping found for ' + m)
}
}
} else {
def old = seenNames[m.deobfuscatedName]
if (old) {
if ((old.length() > 2 || m.obfuscatedName.length() > 2) && old != m.obfuscatedName) {
if (old.length() > 2 && m.obfuscatedName.length() > 2) {
if (KNOWN_WRONG_MAP[m.deobfuscatedName] != m.obfuscatedName) {
println("Duplicate [$old, ${m.obfuscatedName}] -> ${m.deobfuscatedName} in ${m.parent.fullDeobfuscatedName}")
}
} else {
seenNames[m.deobfuscatedName] = m.obfuscatedName.length() > old.length() ? m.obfuscatedName : old
}
}
} else {
seenNames[m.deobfuscatedName] = m.obfuscatedName
}
}
}
}
new File(outDir, 'bukkit_srg.srg').withWriter {
PKG.each { pkg ->
it.writeLine("PK: org/bukkit/craftbukkit/libs/$pkg $pkg")
}
new TSrgWriter(it) {
def remapper = new Remapper() {
@Override
String map(String internalName) {
for (String pkg : PKG) {
if (internalName.startsWith(pkg)) {
return 'org/bukkit/craftbukkit/libs/' + internalName
}
}
return internalName
}
}

@Override
protected void writeClassMapping(ClassMapping<?, ?> mapping) {
if (mapping.fullObfuscatedName.contains('/')) {
super.writeClassMapping(mapping)
}
}

@Override
protected void writeMethodMapping(MethodMapping mapping) {
this.writer.println(String.format("\t%s %s %s",
seenNames.getOrDefault(mapping.getDeobfuscatedName(), mapping.getObfuscatedName()),
remapper.mapMethodDesc(mapping.getObfuscatedDescriptor()),
mapping.getDeobfuscatedName()))
}
}.write(finalMap)
}
new File(outDir, 'bukkit_at.at').withWriter { w ->
Expand All @@ -161,8 +86,8 @@ class ProcessMappingV2Task extends DefaultTask {
w.writeLine("${split[0].replace('inal', '')} ${(finalMap.deobfuscate(new ObjectType(split[1])) as ObjectType).className.replace('/', '.')}")
} else {
def cl = split[1].substring(0, split[1].lastIndexOf('/'))
def f = finalMap.getTopLevelClassMapping(cl)
.flatMap { mcp.getTopLevelClassMapping(it.fullDeobfuscatedName) }
def f = finalMap.getClassMapping(cl)
.flatMap { mcp.getClassMapping(it.fullDeobfuscatedName) }
.flatMap { it.getFieldMapping(name) }
.map { it.deobfuscatedName }
if (f.isEmpty()) {
Expand All @@ -176,7 +101,9 @@ class ProcessMappingV2Task extends DefaultTask {
def s = split[1].substring(0, i)
def cl = s.substring(0, s.lastIndexOf('/'))
def name = s.substring(s.lastIndexOf('/') + 1)
def m = finalMap.getTopLevelClassMapping(cl).flatMap { it.getMethodMapping(name, desc) }
def m = finalMap.getClassMapping(cl)
.flatMap { mcp.getClassMapping(it.fullDeobfuscatedName) }
.map() { it.methodMappings.find { it.obfuscatedName == name } }
if (m.isEmpty()) {
w.writeLine("${name == '<init>' ? '' : '# TODO '}${split[0].replace('inal', '')} ${(finalMap.deobfuscate(new ObjectType(cl)) as ObjectType).className.replace('/', '.')} $name${finalMap.deobfuscate(MethodDescriptor.of(desc))}")
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ class RemapSpigotTask extends DefaultTask {
includes = new ArrayList<>()
includes.add('configurations')
includes.add('META-INF/maven/org.spigotmc')
includes.add('META-INF/services')
includes.add('mojang-translations')
includes.add('org/spigotmc')
includes.add('org/bukkit/craftbukkit')
includes.add('version.json')
Expand Down

0 comments on commit e3648a7

Please sign in to comment.