From 1d0bcfd88f0ae64e91d1fe5733a15982ada48b8c Mon Sep 17 00:00:00 2001 From: Graham Date: Tue, 14 Jan 2020 23:22:55 +0000 Subject: [PATCH] Add PublicKeyTransformer to Bundler --- .../main/java/dev/openrs2/bundler/Bundler.kt | 20 +++++++++++++------ .../java/dev/openrs2/bundler/BundlerModule.kt | 10 ++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 bundler/src/main/java/dev/openrs2/bundler/BundlerModule.kt diff --git a/bundler/src/main/java/dev/openrs2/bundler/Bundler.kt b/bundler/src/main/java/dev/openrs2/bundler/Bundler.kt index 11c0239b80..94c27a64d5 100644 --- a/bundler/src/main/java/dev/openrs2/bundler/Bundler.kt +++ b/bundler/src/main/java/dev/openrs2/bundler/Bundler.kt @@ -1,6 +1,7 @@ package dev.openrs2.bundler import com.github.michaelbull.logging.InlineLogger +import com.google.inject.Guice import dev.openrs2.asm.classpath.ClassPath import dev.openrs2.asm.classpath.Library import dev.openrs2.bundler.transform.BufferSizeTransformer @@ -9,6 +10,7 @@ import dev.openrs2.bundler.transform.HostCheckTransformer import dev.openrs2.bundler.transform.LoadLibraryTransformer import dev.openrs2.bundler.transform.MacResizeTransformer import dev.openrs2.bundler.transform.PlatformDetectionTransformer +import dev.openrs2.bundler.transform.PublicKeyTransformer import dev.openrs2.bundler.transform.ResourceTransformer import dev.openrs2.bundler.transform.RightClickTransformer import java.nio.file.Path @@ -16,14 +18,20 @@ import java.nio.file.Paths import java.util.jar.Attributes import java.util.jar.Attributes.Name.MANIFEST_VERSION import java.util.jar.Manifest +import javax.inject.Inject +import javax.inject.Singleton fun main() { - val bundler = Bundler(Paths.get("nonfree/code"), Paths.get("nonfree/code/bundle")) - bundler.run() + val injector = Guice.createInjector(BundlerModule()) + val bundler = injector.getInstance(Bundler::class.java) + bundler.run(Paths.get("nonfree/code"), Paths.get("nonfree/code/bundle")) } -class Bundler(private val input: Path, private val output: Path) { - fun run() { +@Singleton +class Bundler @Inject constructor(publicKeyTransformer: PublicKeyTransformer) { + private val transformers = listOf(*TRANSFORMERS.toTypedArray(), publicKeyTransformer) + + fun run(input: Path, output: Path) { // read input jars/packs logger.info { "Reading input jars" } val unpacker = Library.readJar(input.resolve("game_unpacker.dat")) @@ -48,13 +56,13 @@ class Bundler(private val input: Path, private val output: Path) { // run simple transformers logger.info { "Transforming client" } - for (transformer in TRANSFORMERS) { + for (transformer in transformers) { logger.info { "Running transformer ${transformer.javaClass.simpleName} " } transformer.transform(classPath) } logger.info { "Transforming client_gl" } - for (transformer in TRANSFORMERS) { + for (transformer in transformers) { logger.info { "Running transformer ${transformer.javaClass.simpleName} " } transformer.transform(glClassPath) } diff --git a/bundler/src/main/java/dev/openrs2/bundler/BundlerModule.kt b/bundler/src/main/java/dev/openrs2/bundler/BundlerModule.kt new file mode 100644 index 0000000000..9cd7759041 --- /dev/null +++ b/bundler/src/main/java/dev/openrs2/bundler/BundlerModule.kt @@ -0,0 +1,10 @@ +package dev.openrs2.bundler + +import com.google.inject.AbstractModule +import dev.openrs2.common.CommonModule + +class BundlerModule : AbstractModule() { + override fun configure() { + install(CommonModule()) + } +}