Add crc32 command

This is useful for checking the CRC-32 checksum of files used by the
loader. It outputs the checksum in signed decimal format, which is the
format used in the file name suffixes in the loader (e.g.
unpackclass_-1911426584.pack).

Signed-off-by: Graham <gpe@openrs2.dev>
Graham 5 years ago
parent c849c5ad46
commit 44fb2ebe25
  1. 1
      all/build.gradle.kts
  2. 2
      all/src/main/java/dev/openrs2/Command.kt
  3. 29
      crc32/build.gradle.kts
  4. 32
      crc32/src/main/java/dev/openrs2/crc32/Crc32Command.kt
  5. 1
      settings.gradle.kts

@ -17,6 +17,7 @@ application {
dependencies { dependencies {
implementation(project(":bundler")) implementation(project(":bundler"))
implementation(project(":compress-cli")) implementation(project(":compress-cli"))
implementation(project(":crc32"))
implementation(project(":decompiler")) implementation(project(":decompiler"))
implementation(project(":deob")) implementation(project(":deob"))
implementation(project(":deob-ast")) implementation(project(":deob-ast"))

@ -4,6 +4,7 @@ import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.subcommands import com.github.ajalt.clikt.core.subcommands
import dev.openrs2.bundler.BundleCommand import dev.openrs2.bundler.BundleCommand
import dev.openrs2.compress.cli.CompressCommand import dev.openrs2.compress.cli.CompressCommand
import dev.openrs2.crc32.Crc32Command
import dev.openrs2.decompiler.DecompileCommand import dev.openrs2.decompiler.DecompileCommand
import dev.openrs2.deob.DeobfuscateCommand import dev.openrs2.deob.DeobfuscateCommand
import dev.openrs2.deob.ast.AstDeobfuscateCommand import dev.openrs2.deob.ast.AstDeobfuscateCommand
@ -12,6 +13,7 @@ import dev.openrs2.game.GameCommand
fun main(args: Array<String>) = Command().subcommands( fun main(args: Array<String>) = Command().subcommands(
BundleCommand(), BundleCommand(),
CompressCommand(), CompressCommand(),
Crc32Command(),
DecompileCommand(), DecompileCommand(),
DeobfuscateCommand(), DeobfuscateCommand(),
AstDeobfuscateCommand(), AstDeobfuscateCommand(),

@ -0,0 +1,29 @@
plugins {
`maven-publish`
application
kotlin("jvm")
}
application {
mainClassName = "dev.openrs2.crc32.Crc32CommandKt"
}
dependencies {
api(project(":cli"))
}
publishing {
publications.create<MavenPublication>("maven") {
from(components["java"])
pom {
packaging = "jar"
name.set("OpenRS2 CRC-32")
description.set(
"""
A tool for calculating the CRC-32 checksum of a file.
""".trimIndent()
)
}
}
}

@ -0,0 +1,32 @@
package dev.openrs2.crc32
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.options.option
import dev.openrs2.cli.defaultStdin
import dev.openrs2.cli.inputStream
import java.util.zip.CRC32
fun main(args: Array<String>) = Crc32Command().main(args)
class Crc32Command : CliktCommand(name = "crc32") {
private val input by option().inputStream().defaultStdin()
override fun run() {
val crc = CRC32()
input.use { input ->
val bytes = ByteArray(4096)
while (true) {
val len = input.read(bytes)
if (len == -1) {
break
}
crc.update(bytes, 0, len)
}
}
echo(crc.value.toInt())
}
}

@ -10,6 +10,7 @@ include(
"common", "common",
"compress", "compress",
"compress-cli", "compress-cli",
"crc32",
"decompiler", "decompiler",
"deob", "deob",
"deob-annotations", "deob-annotations",

Loading…
Cancel
Save