Skip to content

Commit 48a8c81

Browse files
committed
Fix bootstrap mod not working.
1 parent f2d01c8 commit 48a8c81

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

init/build.gradle

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
import org.objectweb.asm.ClassReader
2+
import org.objectweb.asm.ClassWriter
3+
import org.objectweb.asm.Opcodes
4+
import org.objectweb.asm.commons.ClassRemapper
5+
import org.objectweb.asm.commons.Remapper
6+
7+
import java.util.jar.JarEntry
8+
import java.util.jar.JarFile
9+
import java.util.jar.JarOutputStream
10+
11+
buildscript {
12+
dependencies {
13+
classpath "org.ow2.asm:asm-commons:${project['asm.version']}"
14+
}
15+
}
16+
117
plugins {
218
id 'net.ltgt.errorprone'
319
}
@@ -30,6 +46,7 @@ jar {
3046
attributes 'Can-Set-Native-Method-Prefix': 'true'
3147
attributes 'Can-Retransform-Classes': 'true'
3248
attributes 'Can-Redefine-Classes': 'true'
49+
attributes 'Sealed': 'true'
3350
}
3451

3552
from(zipTree(project(":patcher").tasks.jar.archiveFile.get().asFile)) {
@@ -38,6 +55,64 @@ jar {
3855
}
3956

4057
dependsOn(":patcher:jar")
58+
59+
doLast {
60+
def jarFileAsFile = archiveFile.get().asFile
61+
def tempJar = new File(jarFileAsFile.parentFile, jarFileAsFile.name + ".tmp")
62+
def remapper = new Remapper(Opcodes.ASM9) {
63+
@Override
64+
String map(String typeName) {
65+
if (typeName.startsWith("com/fox2code/hypertale/launcher/InternalMicroJsonScanner")) {
66+
return typeName.replaceFirst(
67+
"com/fox2code/hypertale/launcher/", "com/fox2code/hypertale/init/lib/")
68+
}
69+
if (typeName.startsWith("com/fox2code/hypertale/utils/HypertalePlatform")) {
70+
return typeName.replaceFirst(
71+
"com/fox2code/hypertale/utils/", "com/fox2code/hypertale/init/lib/")
72+
}
73+
return super.map(typeName)
74+
}
75+
}
76+
77+
def jf = new JarFile(jarFileAsFile)
78+
def jos = new JarOutputStream(new FileOutputStream(tempJar))
79+
def addedEntries = new HashSet<String>()
80+
81+
jf.entries().each { entry ->
82+
if (entry.isDirectory()) return
83+
84+
def is = jf.getInputStream(entry)
85+
def bytes = is.readAllBytes()
86+
is.close()
87+
88+
def newName = entry.name
89+
90+
if (entry.name.endsWith(".class")) {
91+
def cr = new ClassReader(bytes)
92+
def cw = new ClassWriter(0)
93+
def crMapper = new ClassRemapper(cw, remapper)
94+
cr.accept(crMapper, 0)
95+
bytes = cw.toByteArray()
96+
97+
newName = remapper.map(entry.name.replace(".class", "")) + ".class"
98+
}
99+
100+
// Write to the new temporary JAR
101+
if (addedEntries.add(newName)) {
102+
def newEntry = new JarEntry(newName)
103+
jos.putNextEntry(newEntry)
104+
jos.write(bytes)
105+
jos.closeEntry()
106+
}
107+
}
108+
109+
jos.finish()
110+
jos.close()
111+
jf.close()
112+
113+
jarFileAsFile.delete()
114+
tempJar.renameTo(jarFileAsFile)
115+
}
41116
}
42117

43118
test {

0 commit comments

Comments
 (0)