Use Clikt to implement the command-line interface

Signed-off-by: Graham <gpe@openrs2.dev>
Graham 5 years ago
parent 1552b53ace
commit a52d58e8b5
  1. 2
      .idea/runConfigurations/AstDeobfuscator.xml
  2. 2
      .idea/runConfigurations/Bundler.xml
  3. 2
      .idea/runConfigurations/Decompiler.xml
  4. 2
      .idea/runConfigurations/Deobfuscator.xml
  5. 2
      .idea/runConfigurations/GameServer.xml
  6. 2
      all/build.gradle.kts
  7. 23
      all/src/main/java/dev/openrs2/Command.kt
  8. 39
      all/src/main/java/dev/openrs2/Launcher.kt
  9. 1
      buildSrc/src/main/java/Versions.kt
  10. 3
      bundler/build.gradle.kts
  11. 15
      bundler/src/main/java/dev/openrs2/bundler/BundleCommand.kt
  12. 8
      bundler/src/main/java/dev/openrs2/bundler/Bundler.kt
  13. 4
      decompiler/build.gradle.kts
  14. 33
      decompiler/src/main/java/dev/openrs2/decompiler/DecompileCommand.kt
  15. 25
      decompiler/src/main/java/dev/openrs2/decompiler/Decompiler.kt
  16. 4
      deob-ast/build.gradle.kts
  17. 15
      deob-ast/src/main/java/dev/openrs2/deob/ast/AstDeobfuscator.kt
  18. 22
      deob-ast/src/main/java/dev/openrs2/deob/ast/DeobfuscateAstCommand.kt
  19. 4
      deob/build.gradle.kts
  20. 13
      deob/src/main/java/dev/openrs2/deob/DeobfuscateCommand.kt
  21. 6
      deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt
  22. 4
      game/build.gradle.kts
  23. 14
      game/src/main/java/dev/openrs2/game/GameCommand.kt
  24. 7
      game/src/main/java/dev/openrs2/game/GameServer.kt

@ -6,7 +6,7 @@
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="MAIN_CLASS_NAME" value="dev.openrs2.deob.ast.AstDeobfuscatorKt" />
<option name="MAIN_CLASS_NAME" value="dev.openrs2.deob.ast.DeobfuscateAstCommandKt" />
<option name="WORKING_DIRECTORY" value="" />
<method v="2">
<option name="Make" enabled="true" />

@ -6,7 +6,7 @@
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="MAIN_CLASS_NAME" value="dev.openrs2.bundler.BundlerKt" />
<option name="MAIN_CLASS_NAME" value="dev.openrs2.bundler.BundleCommandKt" />
<option name="WORKING_DIRECTORY" value="" />
<method v="2">
<option name="Make" enabled="true" />

@ -6,7 +6,7 @@
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="MAIN_CLASS_NAME" value="dev.openrs2.decompiler.DecompilerKt" />
<option name="MAIN_CLASS_NAME" value="dev.openrs2.decompiler.DecompileCommandKt" />
<option name="WORKING_DIRECTORY" value="" />
<method v="2">
<option name="Make" enabled="true" />

@ -6,7 +6,7 @@
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="MAIN_CLASS_NAME" value="dev.openrs2.deob.DeobfuscatorKt" />
<option name="MAIN_CLASS_NAME" value="dev.openrs2.deob.DeobfuscateCommandKt" />
<option name="WORKING_DIRECTORY" value="" />
<method v="2">
<option name="Make" enabled="true" />

@ -6,7 +6,7 @@
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="MAIN_CLASS_NAME" value="dev.openrs2.game.GameServerKt" />
<option name="MAIN_CLASS_NAME" value="dev.openrs2.game.GameCommandKt" />
<option name="WORKING_DIRECTORY" value="" />
<method v="2">
<option name="Make" enabled="true" />

@ -11,7 +11,7 @@ plugins {
application {
applicationName = "openrs2"
mainClassName = "dev.openrs2.LauncherKt"
mainClassName = "dev.openrs2.CommandKt"
}
dependencies {

@ -0,0 +1,23 @@
package dev.openrs2
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.subcommands
import dev.openrs2.bundler.BundleCommand
import dev.openrs2.decompiler.DecompileCommand
import dev.openrs2.deob.DeobfuscateCommand
import dev.openrs2.deob.ast.AstDeobfuscateCommand
import dev.openrs2.game.GameCommand
fun main(args: Array<String>) = Command().subcommands(
BundleCommand(),
DecompileCommand(),
DeobfuscateCommand(),
AstDeobfuscateCommand(),
GameCommand()
).main(args)
class Command : CliktCommand(name = "openrs2") {
override fun run() {
// empty
}
}

@ -1,39 +0,0 @@
package dev.openrs2
import kotlin.system.exitProcess
import dev.openrs2.bundler.main as bundlerMain
import dev.openrs2.decompiler.main as decompilerMain
import dev.openrs2.deob.ast.main as astDeobfuscatorMain
import dev.openrs2.deob.main as deobfuscatorMain
import dev.openrs2.game.main as gameMain
fun main(args: Array<String>) {
val command: String
val commandArgs: Array<String>
if (args.isEmpty()) {
command = "game"
commandArgs = emptyArray()
} else {
command = args[0]
commandArgs = args.copyOfRange(1, args.size)
}
when (command) {
"bundle" -> bundlerMain()
"decompile" -> decompilerMain()
"deob" -> deobfuscatorMain()
"deob-ast" -> astDeobfuscatorMain()
"game" -> gameMain()
else -> {
System.err.println("Usage: openrs2 [<command> [<args>]]")
System.err.println()
System.err.println("Commands:")
System.err.println(" bundle")
System.err.println(" decompile")
System.err.println(" deob")
System.err.println(" deob-ast")
System.err.println(" game")
exitProcess(1)
}
}
}

@ -1,6 +1,7 @@
object Versions {
const val asm = "8.0"
const val bouncyCastle = "1.64"
const val clikt = "2.6.0"
const val dependencyLicenseReport = "1.13"
const val fernflower = "1.0.3"
const val guava = "28.2-jre"

@ -5,11 +5,12 @@ plugins {
}
application {
mainClassName = "dev.openrs2.bundler.BundlerKt"
mainClassName = "dev.openrs2.bundler.BundleCommandKt"
}
dependencies {
api(project(":asm"))
api("com.github.ajalt:clikt:${Versions.clikt}")
implementation("dev.openrs2:openrs2-natives-all:${Versions.openrs2Natives}")
}

@ -0,0 +1,15 @@
package dev.openrs2.bundler
import com.github.ajalt.clikt.core.CliktCommand
import com.google.inject.Guice
import java.nio.file.Paths
fun main(args: Array<String>) = BundleCommand().main(args)
class BundleCommand : CliktCommand(name = "bundle") {
override fun run() {
val injector = Guice.createInjector(BundlerModule())
val bundler = injector.getInstance(Bundler::class.java)
bundler.run(Paths.get("nonfree/code"), Paths.get("nonfree/code/bundle"), Paths.get("conf/loader.p12"))
}
}

@ -1,7 +1,6 @@
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
@ -16,19 +15,12 @@ import dev.openrs2.bundler.transform.RightClickTransformer
import dev.openrs2.bundler.transform.TypoTransformer
import dev.openrs2.common.crypto.Pkcs12KeyStore
import java.nio.file.Path
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 injector = Guice.createInjector(BundlerModule())
val bundler = injector.getInstance(Bundler::class.java)
bundler.run(Paths.get("nonfree/code"), Paths.get("nonfree/code/bundle"), Paths.get("conf/loader.p12"))
}
@Singleton
class Bundler @Inject constructor(publicKeyTransformer: PublicKeyTransformer) {
private val transformers = TRANSFORMERS + publicKeyTransformer

@ -5,11 +5,13 @@ plugins {
}
application {
mainClassName = "dev.openrs2.decompiler.DecompilerKt"
mainClassName = "dev.openrs2.decompiler.DecompileCommandKt"
applicationDefaultJvmArgs = listOf("-Xmx3G")
}
dependencies {
api("com.github.ajalt:clikt:${Versions.clikt}")
implementation(project(":common"))
implementation("dev.openrs2:fernflower:${Versions.fernflower}")
}

@ -0,0 +1,33 @@
package dev.openrs2.decompiler
import com.github.ajalt.clikt.core.CliktCommand
import java.nio.file.Path
import java.nio.file.Paths
fun main(args: Array<String>) = DecompileCommand().main(args)
class DecompileCommand : CliktCommand(name = "decompile") {
override fun run() {
val deobOutput = Paths.get("nonfree/code/deob")
val sources = listOf(
deobOutput.resolve("runescape_gl.jar"),
deobOutput.resolve("jaggl.jar"),
deobOutput.resolve("loader_gl.jar"),
deobOutput.resolve("signlink_gl.jar"),
deobOutput.resolve("unpack_gl.jar"),
deobOutput.resolve("unpacker_gl.jar")
)
Decompiler(sources, ::getDestination).use {
it.run()
}
}
private fun getDestination(archive: String): Path {
var dir = archive.replace(Regex("(?:_gl)?[.]jar$"), "")
when (dir) {
"runescape" -> dir = "client"
"jaggl" -> dir = "gl"
}
return Paths.get("nonfree").resolve(dir).resolve("src/main/java")
}
}

@ -4,31 +4,6 @@ import org.jetbrains.java.decompiler.main.Fernflower
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences
import java.io.Closeable
import java.nio.file.Path
import java.nio.file.Paths
private fun getDestination(archive: String): Path {
var dir = archive.replace(Regex("(?:_gl)?[.]jar$"), "")
when (dir) {
"runescape" -> dir = "client"
"jaggl" -> dir = "gl"
}
return Paths.get("nonfree").resolve(dir).resolve("src/main/java")
}
fun main() {
val deobOutput = Paths.get("nonfree/code/deob")
val sources = listOf(
deobOutput.resolve("runescape_gl.jar"),
deobOutput.resolve("jaggl.jar"),
deobOutput.resolve("loader_gl.jar"),
deobOutput.resolve("signlink_gl.jar"),
deobOutput.resolve("unpack_gl.jar"),
deobOutput.resolve("unpacker_gl.jar")
)
Decompiler(sources, ::getDestination).use {
it.run()
}
}
class Decompiler(
private val sources: List<Path>,

@ -5,10 +5,12 @@ plugins {
}
application {
mainClassName = "dev.openrs2.deob.ast.AstDeobfuscatorKt"
mainClassName = "dev.openrs2.deob.ast.DeobfuscateAstCommandKt"
}
dependencies {
api("com.github.ajalt:clikt:${Versions.clikt}")
implementation(project(":common"))
implementation("com.github.javaparser:javaparser-symbol-solver-core:${Versions.javaParser}")
implementation("org.jdom:jdom2:${Versions.jdom}")

@ -25,23 +25,8 @@ import dev.openrs2.deob.ast.transform.TernaryTransformer
import dev.openrs2.deob.ast.transform.UnencloseTransformer
import dev.openrs2.deob.ast.transform.ValueOfTransformer
import java.nio.file.Path
import java.nio.file.Paths
import java.util.function.Function
fun main() {
val deobfuscator = AstDeobfuscator(
listOf(
Paths.get("nonfree/client/src/main/java"),
Paths.get("nonfree/gl/src/main/java"),
Paths.get("nonfree/loader/src/main/java"),
Paths.get("nonfree/signlink/src/main/java"),
Paths.get("nonfree/unpack/src/main/java"),
Paths.get("nonfree/unpacker/src/main/java")
)
)
deobfuscator.run()
}
class AstDeobfuscator(private val modules: List<Path>) {
fun run() {
val solver = CombinedTypeSolver(ReflectionTypeSolver(true))

@ -0,0 +1,22 @@
package dev.openrs2.deob.ast
import com.github.ajalt.clikt.core.CliktCommand
import java.nio.file.Paths
fun main(args: Array<String>) = AstDeobfuscateCommand().main(args)
class AstDeobfuscateCommand : CliktCommand(name = "deob-ast") {
override fun run() {
val deobfuscator = AstDeobfuscator(
listOf(
Paths.get("nonfree/client/src/main/java"),
Paths.get("nonfree/gl/src/main/java"),
Paths.get("nonfree/loader/src/main/java"),
Paths.get("nonfree/signlink/src/main/java"),
Paths.get("nonfree/unpack/src/main/java"),
Paths.get("nonfree/unpacker/src/main/java")
)
)
deobfuscator.run()
}
}

@ -5,10 +5,12 @@ plugins {
}
application {
mainClassName = "dev.openrs2.deob.DeobfuscatorKt"
mainClassName = "dev.openrs2.deob.DeobfuscateCommandKt"
}
dependencies {
api("com.github.ajalt:clikt:${Versions.clikt}")
implementation(project(":bundler"))
implementation(project(":deob-annotations"))
implementation("com.google.guava:guava:${Versions.guava}")

@ -0,0 +1,13 @@
package dev.openrs2.deob
import com.github.ajalt.clikt.core.CliktCommand
import java.nio.file.Paths
fun main(args: Array<String>) = DeobfuscateCommand().main(args)
class DeobfuscateCommand : CliktCommand(name = "deob") {
override fun run() {
val deobfuscator = Deobfuscator(Paths.get("nonfree/code"), Paths.get("nonfree/code/deob"))
deobfuscator.run()
}
}

@ -38,12 +38,6 @@ import dev.openrs2.deob.transform.UnusedMethodTransformer
import dev.openrs2.deob.transform.VisibilityTransformer
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
fun main() {
val deobfuscator = Deobfuscator(Paths.get("nonfree/code"), Paths.get("nonfree/code/deob"))
deobfuscator.run()
}
class Deobfuscator(private val input: Path, private val output: Path) {
fun run() {

@ -5,10 +5,12 @@ plugins {
}
application {
mainClassName = "dev.openrs2.game.GameServerKt"
mainClassName = "dev.openrs2.game.GameCommandKt"
}
dependencies {
api("com.github.ajalt:clikt:${Versions.clikt}")
implementation(project(":common"))
}

@ -0,0 +1,14 @@
package dev.openrs2.game
import com.github.ajalt.clikt.core.CliktCommand
import com.google.inject.Guice
fun main(args: Array<String>) = GameCommand().main(args)
class GameCommand : CliktCommand(name = "game") {
override fun run() {
val injector = Guice.createInjector(GameModule())
val server = injector.getInstance(GameServer::class.java)
server.run()
}
}

@ -1,14 +1,7 @@
package dev.openrs2.game
import com.google.inject.Guice
import javax.inject.Singleton
fun main() {
val injector = Guice.createInjector(GameModule())
val server = injector.getInstance(GameServer::class.java)
server.run()
}
@Singleton
class GameServer {
fun run() {

Loading…
Cancel
Save