diff --git a/.idea/runConfigurations/AstDeobfuscator.xml b/.idea/runConfigurations/AstDeobfuscator.xml
index 598fc5fac6..beef02a612 100644
--- a/.idea/runConfigurations/AstDeobfuscator.xml
+++ b/.idea/runConfigurations/AstDeobfuscator.xml
@@ -6,7 +6,7 @@
-
+
diff --git a/.idea/runConfigurations/Bundler.xml b/.idea/runConfigurations/Bundler.xml
index 435eba25f7..4dff0b1042 100644
--- a/.idea/runConfigurations/Bundler.xml
+++ b/.idea/runConfigurations/Bundler.xml
@@ -6,7 +6,7 @@
-
+
diff --git a/.idea/runConfigurations/Decompiler.xml b/.idea/runConfigurations/Decompiler.xml
index 47a48569e8..70485b5ae5 100644
--- a/.idea/runConfigurations/Decompiler.xml
+++ b/.idea/runConfigurations/Decompiler.xml
@@ -6,7 +6,7 @@
-
+
diff --git a/.idea/runConfigurations/Deobfuscator.xml b/.idea/runConfigurations/Deobfuscator.xml
index c6fbcd1879..0c73742b8e 100644
--- a/.idea/runConfigurations/Deobfuscator.xml
+++ b/.idea/runConfigurations/Deobfuscator.xml
@@ -6,7 +6,7 @@
-
+
diff --git a/.idea/runConfigurations/GameServer.xml b/.idea/runConfigurations/GameServer.xml
index 1e056804f2..d4834d64c2 100644
--- a/.idea/runConfigurations/GameServer.xml
+++ b/.idea/runConfigurations/GameServer.xml
@@ -6,7 +6,7 @@
-
+
diff --git a/all/build.gradle.kts b/all/build.gradle.kts
index e7d852cdfe..d5d1d66ba8 100644
--- a/all/build.gradle.kts
+++ b/all/build.gradle.kts
@@ -11,7 +11,7 @@ plugins {
application {
applicationName = "openrs2"
- mainClassName = "dev.openrs2.LauncherKt"
+ mainClassName = "dev.openrs2.CommandKt"
}
dependencies {
diff --git a/all/src/main/java/dev/openrs2/Command.kt b/all/src/main/java/dev/openrs2/Command.kt
new file mode 100644
index 0000000000..ee68cb204e
--- /dev/null
+++ b/all/src/main/java/dev/openrs2/Command.kt
@@ -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) = Command().subcommands(
+ BundleCommand(),
+ DecompileCommand(),
+ DeobfuscateCommand(),
+ AstDeobfuscateCommand(),
+ GameCommand()
+).main(args)
+
+class Command : CliktCommand(name = "openrs2") {
+ override fun run() {
+ // empty
+ }
+}
diff --git a/all/src/main/java/dev/openrs2/Launcher.kt b/all/src/main/java/dev/openrs2/Launcher.kt
deleted file mode 100644
index c8b24dc886..0000000000
--- a/all/src/main/java/dev/openrs2/Launcher.kt
+++ /dev/null
@@ -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) {
- val command: String
- val commandArgs: Array
- 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 [ []]")
- 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)
- }
- }
-}
diff --git a/buildSrc/src/main/java/Versions.kt b/buildSrc/src/main/java/Versions.kt
index eb5ded4b08..a96c0be8a8 100644
--- a/buildSrc/src/main/java/Versions.kt
+++ b/buildSrc/src/main/java/Versions.kt
@@ -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"
diff --git a/bundler/build.gradle.kts b/bundler/build.gradle.kts
index 2c1fa08c67..ca3718593d 100644
--- a/bundler/build.gradle.kts
+++ b/bundler/build.gradle.kts
@@ -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}")
}
diff --git a/bundler/src/main/java/dev/openrs2/bundler/BundleCommand.kt b/bundler/src/main/java/dev/openrs2/bundler/BundleCommand.kt
new file mode 100644
index 0000000000..b7b071c459
--- /dev/null
+++ b/bundler/src/main/java/dev/openrs2/bundler/BundleCommand.kt
@@ -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) = 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"))
+ }
+}
diff --git a/bundler/src/main/java/dev/openrs2/bundler/Bundler.kt b/bundler/src/main/java/dev/openrs2/bundler/Bundler.kt
index 58a4e3ff04..c7c4086476 100644
--- a/bundler/src/main/java/dev/openrs2/bundler/Bundler.kt
+++ b/bundler/src/main/java/dev/openrs2/bundler/Bundler.kt
@@ -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
diff --git a/decompiler/build.gradle.kts b/decompiler/build.gradle.kts
index c63601f3d7..bf7a20b2d0 100644
--- a/decompiler/build.gradle.kts
+++ b/decompiler/build.gradle.kts
@@ -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}")
}
diff --git a/decompiler/src/main/java/dev/openrs2/decompiler/DecompileCommand.kt b/decompiler/src/main/java/dev/openrs2/decompiler/DecompileCommand.kt
new file mode 100644
index 0000000000..90d69ed907
--- /dev/null
+++ b/decompiler/src/main/java/dev/openrs2/decompiler/DecompileCommand.kt
@@ -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) = 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")
+ }
+}
diff --git a/decompiler/src/main/java/dev/openrs2/decompiler/Decompiler.kt b/decompiler/src/main/java/dev/openrs2/decompiler/Decompiler.kt
index eab44f4c0d..cf29f778d5 100644
--- a/decompiler/src/main/java/dev/openrs2/decompiler/Decompiler.kt
+++ b/decompiler/src/main/java/dev/openrs2/decompiler/Decompiler.kt
@@ -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,
diff --git a/deob-ast/build.gradle.kts b/deob-ast/build.gradle.kts
index 2ae9419a9b..457b8f20ce 100644
--- a/deob-ast/build.gradle.kts
+++ b/deob-ast/build.gradle.kts
@@ -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}")
diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/AstDeobfuscator.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/AstDeobfuscator.kt
index b80d4590ce..57dfafb0a3 100644
--- a/deob-ast/src/main/java/dev/openrs2/deob/ast/AstDeobfuscator.kt
+++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/AstDeobfuscator.kt
@@ -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) {
fun run() {
val solver = CombinedTypeSolver(ReflectionTypeSolver(true))
diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/DeobfuscateAstCommand.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/DeobfuscateAstCommand.kt
new file mode 100644
index 0000000000..91119f0ad1
--- /dev/null
+++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/DeobfuscateAstCommand.kt
@@ -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) = 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()
+ }
+}
diff --git a/deob/build.gradle.kts b/deob/build.gradle.kts
index 4e61440328..691738c7d5 100644
--- a/deob/build.gradle.kts
+++ b/deob/build.gradle.kts
@@ -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}")
diff --git a/deob/src/main/java/dev/openrs2/deob/DeobfuscateCommand.kt b/deob/src/main/java/dev/openrs2/deob/DeobfuscateCommand.kt
new file mode 100644
index 0000000000..5c7d968d64
--- /dev/null
+++ b/deob/src/main/java/dev/openrs2/deob/DeobfuscateCommand.kt
@@ -0,0 +1,13 @@
+package dev.openrs2.deob
+
+import com.github.ajalt.clikt.core.CliktCommand
+import java.nio.file.Paths
+
+fun main(args: Array) = 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()
+ }
+}
diff --git a/deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt b/deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt
index 6c4a2e6c3c..66bfc63129 100644
--- a/deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt
+++ b/deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt
@@ -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() {
diff --git a/game/build.gradle.kts b/game/build.gradle.kts
index 720637341d..8956db2322 100644
--- a/game/build.gradle.kts
+++ b/game/build.gradle.kts
@@ -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"))
}
diff --git a/game/src/main/java/dev/openrs2/game/GameCommand.kt b/game/src/main/java/dev/openrs2/game/GameCommand.kt
new file mode 100644
index 0000000000..101e2a64ca
--- /dev/null
+++ b/game/src/main/java/dev/openrs2/game/GameCommand.kt
@@ -0,0 +1,14 @@
+package dev.openrs2.game
+
+import com.github.ajalt.clikt.core.CliktCommand
+import com.google.inject.Guice
+
+fun main(args: Array) = 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()
+ }
+}
diff --git a/game/src/main/java/dev/openrs2/game/GameServer.kt b/game/src/main/java/dev/openrs2/game/GameServer.kt
index c5371addee..9aedc99369 100644
--- a/game/src/main/java/dev/openrs2/game/GameServer.kt
+++ b/game/src/main/java/dev/openrs2/game/GameServer.kt
@@ -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() {