From ae7c19beacef6076634bf33d0a0f566c9d865ed5 Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 2 May 2020 23:12:46 +0100 Subject: [PATCH] Convert most Library{Reader,Writer} implementations to objects Signed-off-by: Graham --- .../dev/openrs2/asm/io/JarLibraryReader.kt | 8 +++----- .../dev/openrs2/asm/io/JarLibraryWriter.kt | 2 +- .../dev/openrs2/asm/io/Js5LibraryWriter.kt | 2 +- .../dev/openrs2/asm/io/Pack200LibraryReader.kt | 4 ++-- .../dev/openrs2/asm/io/Pack200LibraryWriter.kt | 4 ++-- .../main/java/dev/openrs2/bundler/Bundler.kt | 18 +++++++++--------- .../main/java/dev/openrs2/deob/Deobfuscator.kt | 6 +++--- 7 files changed, 21 insertions(+), 23 deletions(-) diff --git a/asm/src/main/java/dev/openrs2/asm/io/JarLibraryReader.kt b/asm/src/main/java/dev/openrs2/asm/io/JarLibraryReader.kt index 9566c63b5c..645f761b07 100644 --- a/asm/src/main/java/dev/openrs2/asm/io/JarLibraryReader.kt +++ b/asm/src/main/java/dev/openrs2/asm/io/JarLibraryReader.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" - } } diff --git a/asm/src/main/java/dev/openrs2/asm/io/JarLibraryWriter.kt b/asm/src/main/java/dev/openrs2/asm/io/JarLibraryWriter.kt index baac374506..e2c5a34867 100644 --- a/asm/src/main/java/dev/openrs2/asm/io/JarLibraryWriter.kt +++ b/asm/src/main/java/dev/openrs2/asm/io/JarLibraryWriter.kt @@ -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) } diff --git a/asm/src/main/java/dev/openrs2/asm/io/Js5LibraryWriter.kt b/asm/src/main/java/dev/openrs2/asm/io/Js5LibraryWriter.kt index 5e49969e9b..bea7a99a37 100644 --- a/asm/src/main/java/dev/openrs2/asm/io/Js5LibraryWriter.kt +++ b/asm/src/main/java/dev/openrs2/asm/io/Js5LibraryWriter.kt @@ -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 } diff --git a/asm/src/main/java/dev/openrs2/asm/io/Pack200LibraryReader.kt b/asm/src/main/java/dev/openrs2/asm/io/Pack200LibraryReader.kt index 0dbd0cf00f..9d7d513102 100644 --- a/asm/src/main/java/dev/openrs2/asm/io/Pack200LibraryReader.kt +++ b/asm/src/main/java/dev/openrs2/asm/io/Pack200LibraryReader.kt @@ -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) } } } diff --git a/asm/src/main/java/dev/openrs2/asm/io/Pack200LibraryWriter.kt b/asm/src/main/java/dev/openrs2/asm/io/Pack200LibraryWriter.kt index 5c3f2077e0..7fd40c3a1f 100644 --- a/asm/src/main/java/dev/openrs2/asm/io/Pack200LibraryWriter.kt +++ b/asm/src/main/java/dev/openrs2/asm/io/Pack200LibraryWriter.kt @@ -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 -> diff --git a/bundler/src/main/java/dev/openrs2/bundler/Bundler.kt b/bundler/src/main/java/dev/openrs2/bundler/Bundler.kt index a1e0fd1cab..3f7d529a4c 100644 --- a/bundler/src/main/java/dev/openrs2/bundler/Bundler.kt +++ b/bundler/src/main/java/dev/openrs2/bundler/Bundler.kt @@ -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) } } diff --git a/deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt b/deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt index 8d0e115994..a7607db57b 100644 --- a/deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt +++ b/deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt @@ -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) } }