From 3e60a82ca1be256c750674186d661512db6d7a5f Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 2 Apr 2022 10:08:07 +0100 Subject: [PATCH] Add command for unpacking RuneLite flatcaches Signed-off-by: Graham --- all/build.gradle.kts | 1 + all/src/main/kotlin/org/openrs2/Command.kt | 2 ++ cache-cli/build.gradle.kts | 32 +++++++++++++++++++ .../org/openrs2/cache/cli/CacheCommand.kt | 14 ++++++++ .../cache/cli/RuneLiteUnpackCommand.kt | 27 ++++++++++++++++ settings.gradle.kts | 1 + 6 files changed, 77 insertions(+) create mode 100644 cache-cli/build.gradle.kts create mode 100644 cache-cli/src/main/kotlin/org/openrs2/cache/cli/CacheCommand.kt create mode 100644 cache-cli/src/main/kotlin/org/openrs2/cache/cli/RuneLiteUnpackCommand.kt diff --git a/all/build.gradle.kts b/all/build.gradle.kts index fcc0d71767..03832ff753 100644 --- a/all/build.gradle.kts +++ b/all/build.gradle.kts @@ -17,6 +17,7 @@ application { dependencies { implementation(projects.archive) implementation(projects.bufferGenerator) + implementation(projects.cacheCli) implementation(projects.compressCli) implementation(projects.crc32) implementation(projects.deob) diff --git a/all/src/main/kotlin/org/openrs2/Command.kt b/all/src/main/kotlin/org/openrs2/Command.kt index 7a83abc1bc..25ab8841b6 100644 --- a/all/src/main/kotlin/org/openrs2/Command.kt +++ b/all/src/main/kotlin/org/openrs2/Command.kt @@ -4,6 +4,7 @@ import com.github.ajalt.clikt.core.NoOpCliktCommand import com.github.ajalt.clikt.core.subcommands import org.openrs2.archive.ArchiveCommand import org.openrs2.buffer.generator.GenerateBufferCommand +import org.openrs2.cache.cli.CacheCommand import org.openrs2.compress.cli.CompressCommand import org.openrs2.crc32.Crc32Command import org.openrs2.deob.DeobfuscateCommand @@ -16,6 +17,7 @@ public class Command : NoOpCliktCommand(name = "openrs2") { init { subcommands( ArchiveCommand(), + CacheCommand(), CompressCommand(), Crc32Command(), DeobfuscateCommand(), diff --git a/cache-cli/build.gradle.kts b/cache-cli/build.gradle.kts new file mode 100644 index 0000000000..2c78abdc71 --- /dev/null +++ b/cache-cli/build.gradle.kts @@ -0,0 +1,32 @@ +plugins { + `maven-publish` + application + kotlin("jvm") +} + +application { + mainClass.set("org.openrs2.cache.cli.CacheCommandKt") +} + +dependencies { + api(libs.clikt) + + implementation(projects.cache) + implementation(projects.inject) +} + +publishing { + publications.create("maven") { + from(components["java"]) + + pom { + packaging = "jar" + name.set("OpenRS2 Cache CLI") + description.set( + """ + Tools for working with RuneScape caches. + """.trimIndent() + ) + } + } +} diff --git a/cache-cli/src/main/kotlin/org/openrs2/cache/cli/CacheCommand.kt b/cache-cli/src/main/kotlin/org/openrs2/cache/cli/CacheCommand.kt new file mode 100644 index 0000000000..d7a396d621 --- /dev/null +++ b/cache-cli/src/main/kotlin/org/openrs2/cache/cli/CacheCommand.kt @@ -0,0 +1,14 @@ +package org.openrs2.cache.cli + +import com.github.ajalt.clikt.core.NoOpCliktCommand +import com.github.ajalt.clikt.core.subcommands + +public fun main(args: Array): Unit = CacheCommand().main(args) + +public class CacheCommand : NoOpCliktCommand(name = "cache") { + init { + subcommands( + RuneLiteUnpackCommand() + ) + } +} diff --git a/cache-cli/src/main/kotlin/org/openrs2/cache/cli/RuneLiteUnpackCommand.kt b/cache-cli/src/main/kotlin/org/openrs2/cache/cli/RuneLiteUnpackCommand.kt new file mode 100644 index 0000000000..0ba61e3e85 --- /dev/null +++ b/cache-cli/src/main/kotlin/org/openrs2/cache/cli/RuneLiteUnpackCommand.kt @@ -0,0 +1,27 @@ +package org.openrs2.cache.cli + +import com.github.ajalt.clikt.core.CliktCommand +import com.github.ajalt.clikt.parameters.arguments.argument +import com.github.ajalt.clikt.parameters.types.path +import com.google.inject.Guice +import io.netty.buffer.ByteBufAllocator +import org.openrs2.cache.CacheModule +import org.openrs2.cache.RuneLiteStore +import org.openrs2.cache.Store +import org.openrs2.inject.CloseableInjector + +public class RuneLiteUnpackCommand : CliktCommand(name = "unpack-runelite") { + private val input by argument().path(mustExist = true, canBeFile = false, mustBeReadable = true) + private val output by argument().path(canBeFile = false, mustBeReadable = true, mustBeWritable = true) + + override fun run() { + CloseableInjector(Guice.createInjector(CacheModule)).use { injector -> + val alloc = injector.getInstance(ByteBufAllocator::class.java) + val runeLiteStore = injector.getInstance(RuneLiteStore::class.java) + + Store.open(output, alloc).use { store -> + runeLiteStore.unpack(input, store) + } + } + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index faefb546b4..b62b43b079 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -28,6 +28,7 @@ include( "buffer-generator", "cache", "cache-550", + "cache-cli", "cli", "compress", "compress-cli",