diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/AstDeobfuscatorModule.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/AstDeobfuscatorModule.kt index 85e19018..b20a9b49 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/AstDeobfuscatorModule.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/AstDeobfuscatorModule.kt @@ -1,7 +1,10 @@ package dev.openrs2.deob.ast import com.google.inject.AbstractModule +import com.google.inject.Scopes import com.google.inject.multibindings.Multibinder +import dev.openrs2.deob.ast.gl.GlRegistry +import dev.openrs2.deob.ast.gl.GlRegistryProvider import dev.openrs2.deob.ast.transform.AddSubTransformer import dev.openrs2.deob.ast.transform.BinaryExprOrderTransformer import dev.openrs2.deob.ast.transform.BitMaskTransformer @@ -21,6 +24,10 @@ import dev.openrs2.deob.ast.transform.ValueOfTransformer object AstDeobfuscatorModule : AbstractModule() { override fun configure() { + bind(GlRegistry::class.java) + .toProvider(GlRegistryProvider::class.java) + .`in`(Scopes.SINGLETON) + val binder = Multibinder.newSetBinder(binder(), Transformer::class.java) binder.addBinding().to(UnencloseTransformer::class.java) binder.addBinding().to(NegativeLiteralTransformer::class.java) diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/gl/GlRegistry.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/gl/GlRegistry.kt index e540f2ce..2e3d2e78 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/gl/GlRegistry.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/gl/GlRegistry.kt @@ -23,10 +23,6 @@ data class GlRegistry(val enums: ImmutableSetMultimap, val command } } - fun parse(): GlRegistry { - return GlRegistry::class.java.getResourceAsStream("/dev/openrs2/deob/ast/gl.xml").use(::parse) - } - fun parse(input: InputStream): GlRegistry { val root = SAXBuilder().build(input).rootElement diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/gl/GlRegistryProvider.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/gl/GlRegistryProvider.kt new file mode 100644 index 00000000..71575d4e --- /dev/null +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/gl/GlRegistryProvider.kt @@ -0,0 +1,15 @@ +package dev.openrs2.deob.ast.gl + +import javax.inject.Provider + +class GlRegistryProvider : Provider { + override fun get(): GlRegistry { + GlRegistryProvider::class.java.getResourceAsStream(PATH).use { input -> + return GlRegistry.parse(input) + } + } + + companion object { + private const val PATH = "/dev/openrs2/deob/ast/gl.xml" + } +} diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/GlTransformer.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/GlTransformer.kt index 079a621b..bcafb686 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/GlTransformer.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/GlTransformer.kt @@ -25,10 +25,11 @@ import dev.openrs2.deob.ast.gl.GlParameter import dev.openrs2.deob.ast.gl.GlRegistry import dev.openrs2.deob.ast.util.checkedAsInt import dev.openrs2.deob.ast.util.walk +import javax.inject.Inject import javax.inject.Singleton @Singleton -class GlTransformer(private val registry: GlRegistry = GlRegistry.parse()) : Transformer() { +class GlTransformer @Inject constructor(private val registry: GlRegistry) : Transformer() { private val enums = mutableSetOf() override fun preTransform(units: Map) {