Convert most Library{Reader,Writer} implementations to objects

Signed-off-by: Graham <gpe@openrs2.dev>
Graham 5 years ago
parent 17bc1e287b
commit ae7c19beac
  1. 8
      asm/src/main/java/dev/openrs2/asm/io/JarLibraryReader.kt
  2. 2
      asm/src/main/java/dev/openrs2/asm/io/JarLibraryWriter.kt
  3. 2
      asm/src/main/java/dev/openrs2/asm/io/Js5LibraryWriter.kt
  4. 4
      asm/src/main/java/dev/openrs2/asm/io/Pack200LibraryReader.kt
  5. 4
      asm/src/main/java/dev/openrs2/asm/io/Pack200LibraryWriter.kt
  6. 18
      bundler/src/main/java/dev/openrs2/bundler/Bundler.kt
  7. 6
      deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt

@ -8,7 +8,9 @@ import org.objectweb.asm.tree.ClassNode
import java.io.InputStream
import java.util.jar.JarInputStream
class JarLibraryReader : LibraryReader {
object JarLibraryReader : LibraryReader {
private const val CLASS_SUFFIX = ".class"
override fun read(input: InputStream): Library {
val library = Library()
@ -28,8 +30,4 @@ class JarLibraryReader : LibraryReader {
return library
}
private companion object {
private const val CLASS_SUFFIX = ".class"
}
}

@ -4,7 +4,7 @@ import dev.openrs2.util.io.DeterministicJarOutputStream
import java.io.OutputStream
import java.util.jar.JarOutputStream
class JarLibraryWriter : AbstractJarLibraryWriter() {
object JarLibraryWriter : AbstractJarLibraryWriter() {
override fun createJarOutputStream(output: OutputStream): JarOutputStream {
return DeterministicJarOutputStream(output)
}

@ -4,7 +4,7 @@ import dev.openrs2.asm.classpath.ClassPath
import dev.openrs2.asm.classpath.Library
import java.io.OutputStream
class Js5LibraryWriter : LibraryWriter {
object Js5LibraryWriter : LibraryWriter {
override fun write(output: OutputStream, classPath: ClassPath, library: Library) {
// TODO(gpe): implement
}

@ -8,7 +8,7 @@ import java.io.InputStream
import java.util.jar.JarOutputStream
import java.util.jar.Pack200
class Pack200LibraryReader : LibraryReader {
object Pack200LibraryReader : LibraryReader {
override fun read(input: InputStream): Library {
ByteArrayOutputStream().use { tempOutput ->
Gzip.createHeaderlessInputStream(input).use { gzipInput ->
@ -18,7 +18,7 @@ class Pack200LibraryReader : LibraryReader {
}
return ByteArrayInputStream(tempOutput.toByteArray()).use { tempInput ->
JarLibraryReader().read(tempInput)
JarLibraryReader.read(tempInput)
}
}
}

@ -9,10 +9,10 @@ import java.io.OutputStream
import java.util.jar.JarInputStream
import java.util.jar.Pack200
class Pack200LibraryWriter : LibraryWriter {
object Pack200LibraryWriter : LibraryWriter {
override fun write(output: OutputStream, classPath: ClassPath, library: Library) {
ByteArrayOutputStream().use { tempOutput ->
JarLibraryWriter().write(tempOutput, classPath, library)
JarLibraryWriter.write(tempOutput, classPath, library)
return JarInputStream(ByteArrayInputStream(tempOutput.toByteArray())).use { jarInput ->
Gzip.createHeaderlessOutputStream(output).use { gzipOutput ->

@ -79,25 +79,25 @@ class Bundler @Inject constructor(
logger.info { "Compressing resources" }
val unpackerJar = Resource.compressLibrary(
"unpackclass.pack", "game_unpacker.dat", classPath, unpacker, JarLibraryWriter()
"unpackclass.pack", "game_unpacker.dat", classPath, unpacker, JarLibraryWriter
)
val clientPack = Resource.compressLibrary(
"runescape.pack200", "main_file_cache.dat0", classPath, client, Pack200LibraryWriter()
"runescape.pack200", "main_file_cache.dat0", classPath, client, Pack200LibraryWriter
)
val clientJs5 = Resource.compressLibrary(
"runescape.js5", "main_file_cache.dat1", classPath, client, Js5LibraryWriter()
"runescape.js5", "main_file_cache.dat1", classPath, client, Js5LibraryWriter
)
val glClientPack = Resource.compressLibrary(
"runescape_gl.pack200", "main_file_cache.dat3", glClassPath, glClient, Pack200LibraryWriter()
"runescape_gl.pack200", "main_file_cache.dat3", glClassPath, glClient, Pack200LibraryWriter
)
val glClientJs5 = Resource.compressLibrary(
"runescape_gl.js5", "main_file_cache.dat4", glClassPath, glClient, Js5LibraryWriter()
"runescape_gl.js5", "main_file_cache.dat4", glClassPath, glClient, Js5LibraryWriter
)
val glPack = Resource.compressLibrary(
"jaggl.pack200", "main_file_cache.dat5", glClassPath, gl, Pack200LibraryWriter()
"jaggl.pack200", "main_file_cache.dat5", glClassPath, gl, Pack200LibraryWriter
)
val glJs5 = Resource.compressLibrary(
"jaggl.js5", "main_file_cache.dat6", glClassPath, gl, Js5LibraryWriter()
"jaggl.js5", "main_file_cache.dat6", glClassPath, gl, Js5LibraryWriter
)
val glNatives = Resource.compressGlNatives()
@ -150,7 +150,7 @@ class Bundler @Inject constructor(
logger.info { "Reading jar $path" }
return Files.newInputStream(path).use { input ->
JarLibraryReader().read(input)
JarLibraryReader.read(input)
}
}
@ -158,7 +158,7 @@ class Bundler @Inject constructor(
logger.info { "Reading pack $path" }
return Files.newInputStream(path).use { input ->
Pack200LibraryReader().read(input)
Pack200LibraryReader.read(input)
}
}

@ -123,7 +123,7 @@ class Deobfuscator @Inject constructor(
logger.info { "Reading jar $path" }
return Files.newInputStream(path).use { input ->
JarLibraryReader().read(input)
JarLibraryReader.read(input)
}
}
@ -131,7 +131,7 @@ class Deobfuscator @Inject constructor(
logger.info { "Reading pack $path" }
return Files.newInputStream(path).use { input ->
Pack200LibraryReader().read(input)
Pack200LibraryReader.read(input)
}
}
@ -139,7 +139,7 @@ class Deobfuscator @Inject constructor(
logger.info { "Writing jar $path" }
Files.newOutputStream(path).use { output ->
JarLibraryWriter().write(output, classPath, library)
JarLibraryWriter.write(output, classPath, library)
}
}

Loading…
Cancel
Save