Replace runescape.com with domain from the config file

Signed-off-by: Graham <gpe@openrs2.dev>
Graham 5 years ago
parent fe3a8c1a37
commit ef5db18ea1
  1. 2
      bundler/src/main/java/dev/openrs2/bundler/BundlerModule.kt
  2. 51
      bundler/src/main/java/dev/openrs2/bundler/transform/DomainTransformer.kt

@ -5,6 +5,7 @@ import com.google.inject.multibindings.Multibinder
import dev.openrs2.asm.transform.Transformer import dev.openrs2.asm.transform.Transformer
import dev.openrs2.bundler.transform.BufferSizeTransformer import dev.openrs2.bundler.transform.BufferSizeTransformer
import dev.openrs2.bundler.transform.CachePathTransformer import dev.openrs2.bundler.transform.CachePathTransformer
import dev.openrs2.bundler.transform.DomainTransformer
import dev.openrs2.bundler.transform.HostCheckTransformer import dev.openrs2.bundler.transform.HostCheckTransformer
import dev.openrs2.bundler.transform.LoadLibraryTransformer import dev.openrs2.bundler.transform.LoadLibraryTransformer
import dev.openrs2.bundler.transform.MacResizeTransformer import dev.openrs2.bundler.transform.MacResizeTransformer
@ -24,6 +25,7 @@ object BundlerModule : AbstractModule() {
binder.addBinding().to(BufferSizeTransformer::class.java) binder.addBinding().to(BufferSizeTransformer::class.java)
binder.addBinding().to(CachePathTransformer::class.java) binder.addBinding().to(CachePathTransformer::class.java)
binder.addBinding().to(HostCheckTransformer::class.java) binder.addBinding().to(HostCheckTransformer::class.java)
binder.addBinding().to(DomainTransformer::class.java)
binder.addBinding().to(LoadLibraryTransformer::class.java) binder.addBinding().to(LoadLibraryTransformer::class.java)
binder.addBinding().to(MacResizeTransformer::class.java) binder.addBinding().to(MacResizeTransformer::class.java)
binder.addBinding().to(PlatformDetectionTransformer::class.java) binder.addBinding().to(PlatformDetectionTransformer::class.java)

@ -0,0 +1,51 @@
package dev.openrs2.bundler.transform
import com.github.michaelbull.logging.InlineLogger
import dev.openrs2.asm.classpath.ClassPath
import dev.openrs2.asm.classpath.Library
import dev.openrs2.asm.transform.Transformer
import dev.openrs2.conf.Config
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.LdcInsnNode
import org.objectweb.asm.tree.MethodNode
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class DomainTransformer @Inject constructor(
private val config: Config
) : Transformer() {
private var domains = 0
override fun preTransform(classPath: ClassPath) {
domains = 0
}
override fun transformCode(classPath: ClassPath, library: Library, clazz: ClassNode, method: MethodNode): Boolean {
for (insn in method.instructions) {
if (insn !is LdcInsnNode) {
continue
}
val cst = insn.cst
if (cst !is String) {
continue
}
insn.cst = cst.replace("runescape.com", config.domain)
if (insn.cst != cst) {
domains++
}
}
return false
}
override fun postTransform(classPath: ClassPath) {
logger.info { "Replaced $domains domains" }
}
companion object {
private val logger = InlineLogger()
}
}
Loading…
Cancel
Save