Skip to content

Commit bb743d8

Browse files
Merge pull request #14 from runetopic/development
Development
2 parents 29026d7 + 54f4c10 commit bb743d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+231
-218
lines changed

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ A cache library written in Kotlin.
2929
# Implementation
3030
Just use cache if you do not require any of the revision specific loaders.
3131
```
32-
cache = { module = "com.runetopic.cache:cache", version.ref "1.4.6-SNAPSHOT" }
33-
loader = { module = "com.runetopic.cache:loader", version.ref "647.6.0-SNAPSHOT" }
32+
cache = { module = "com.runetopic.cache:cache", version.ref "1.4.7-SNAPSHOT" }
33+
loader = { module = "com.runetopic.cache:loader", version.ref "647.6.1-SNAPSHOT" }
3434
3535
//For the SNAPSHOTS
3636
maven {
@@ -41,9 +41,9 @@ maven {
4141
# Usage
4242
Index -> Group -> File
4343

44-
### Creating a new store
44+
### Creating a new JS5 store
4545
```
46-
val store = Store(File("/filepath/"))
46+
val store = Js5Store(Path.of("/path/"))
4747
```
4848

4949
### Getting an index
@@ -101,6 +101,13 @@ val file = group.getFile(fileId = 1000)
101101
### Getting 255, 255 checksums without RSA/Whirlpool
102102
```val checksums = store.checksumsWithoutRSA()```
103103

104+
### Decompressing a group
105+
```
106+
val index = store.index(indexId = 5)
107+
val group = index.getGroup(groupName = "m50_50")
108+
val decompressed = group.getData().decompress()
109+
```
110+
104111
### An example of a single thread loading providers
105112
```
106113
objs().load(store)

cache/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
signing
55
}
66

7-
version = "1.4.6-SNAPSHOT"
7+
version = "1.4.7-SNAPSHOT"
88

99
java {
1010
withJavadocJar()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.runetopic.cache.codec
2+
3+
import com.runetopic.cache.codec.impl.BZip2Codec
4+
import com.runetopic.cache.codec.impl.GZipCodec
5+
import com.runetopic.cache.codec.impl.NoFileCodec
6+
7+
/**
8+
* @author Tyler Telis
9+
* @email <[email protected]>
10+
*
11+
* @author Jordan Abraham
12+
*/
13+
internal sealed class CodecType(
14+
val codec: IFileCodec
15+
) {
16+
object BadCodec: CodecType(NoFileCodec())
17+
object NoCodec: CodecType(NoFileCodec())
18+
object BZipCodec: CodecType(BZip2Codec())
19+
object GZipCodec: CodecType(GZipCodec())
20+
}

cache/src/main/kotlin/com/runetopic/cache/compression/Container.kt renamed to cache/src/main/kotlin/com/runetopic/cache/codec/Container.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package com.runetopic.cache.compression
1+
package com.runetopic.cache.codec
22

33
/**
44
* @author Tyler Telis
55
* @email <[email protected]>
66
*/
7-
data class Container(
7+
internal data class Container(
88
val data: ByteArray,
99
val compression: Int,
1010
val revision: Int,

cache/src/main/kotlin/com/runetopic/cache/compression/Compression.kt renamed to cache/src/main/kotlin/com/runetopic/cache/codec/ContainerCodec.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package com.runetopic.cache.compression
1+
package com.runetopic.cache.codec
22

3-
import com.runetopic.cache.compression.CompressionType.*
3+
import com.runetopic.cache.codec.CodecType.*
44
import com.runetopic.cache.exception.CompressionException
55
import com.runetopic.cache.extension.readUnsignedShort
66
import com.runetopic.cache.extension.remainingBytes
@@ -14,9 +14,9 @@ import java.util.zip.CRC32
1414
*
1515
* @author Jordan Abraham
1616
*/
17-
object Compression {
17+
internal object ContainerCodec {
1818

19-
fun decompress(data: ByteArray, keys: Array<Int>): Container {
19+
fun decompress(data: ByteArray, keys: IntArray = intArrayOf()): Container {
2020
val buffer = ByteBuffer.wrap(data)
2121

2222
val compression = buffer.get().toInt() and 0xFF
@@ -30,22 +30,22 @@ object Compression {
3030
crc32.update(data, 0, 5)
3131

3232
return when (val type = compressionType(compression)) {
33-
BadCompression -> throw CompressionException("Compression type not found with a compression opcode of $compression.")
34-
is NoCompression -> {
33+
BadCodec -> throw CompressionException("Compression type not found with a compression opcode of $compression.")
34+
is NoCodec -> {
3535
val encrypted = ByteArray(length)
3636
buffer.get(encrypted, 0, length)
3737
crc32.update(encrypted, 0, length)
38-
val decrypted = if (keys.isEmpty()) encrypted else encrypted.fromXTEA(32, keys.toIntArray())
38+
val decrypted = if (keys.isEmpty()) encrypted else encrypted.fromXTEA(32, keys)
3939

4040
val revision = -1 /*buffer.short.toInt() and 0xFFFF*/
4141

4242
Container(decrypted, compression, revision, crc32.value.toInt())
4343
}
44-
GZipCompression, BZipCompression-> {
44+
GZipCodec, BZipCodec-> {
4545
val encrypted = ByteArray(length + 4)
4646
buffer.get(encrypted)
4747
crc32.update(encrypted, 0, encrypted.size)
48-
val decrypted = if (keys.isEmpty()) encrypted else encrypted.fromXTEA(32, keys.toIntArray())
48+
val decrypted = if (keys.isEmpty()) encrypted else encrypted.fromXTEA(32, keys)
4949

5050
var revision = -1
5151

@@ -66,12 +66,12 @@ object Compression {
6666
}
6767
}
6868

69-
private fun compressionType(compression: Int): CompressionType {
69+
private fun compressionType(compression: Int): CodecType {
7070
return when (compression) {
71-
0 -> NoCompression
72-
1 -> BZipCompression
73-
2 -> GZipCompression
74-
else -> BadCompression
71+
0 -> NoCodec
72+
1 -> BZipCodec
73+
2 -> GZipCodec
74+
else -> BadCodec
7575
}
7676
}
7777
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@file:JvmName("Decompression")
2+
package com.runetopic.cache.codec
3+
4+
/**
5+
* @author Jordan Abraham
6+
*/
7+
fun ByteArray.decompress(keys: IntArray = intArrayOf()): ByteArray {
8+
return ContainerCodec.decompress(this, keys).data
9+
}
10+
11+
fun ByteArray.decompress(): ByteArray {
12+
return ContainerCodec.decompress(this, intArrayOf()).data
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.runetopic.cache.codec
2+
3+
/**
4+
* @author Tyler Telis
5+
* @email <[email protected]>
6+
*/
7+
internal interface IFileCodec {
8+
fun compress(data: ByteArray, length: Int, keys: IntArray): ByteArray
9+
fun decompress(data: ByteArray, length: Int, keys: IntArray): ByteArray
10+
}

cache/src/main/kotlin/com/runetopic/cache/compression/impl/BZip2Codec.kt renamed to cache/src/main/kotlin/com/runetopic/cache/codec/impl/BZip2Codec.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package com.runetopic.cache.compression.impl
1+
package com.runetopic.cache.codec.impl
22

3-
import com.runetopic.cache.compression.IFileCodec
3+
import com.runetopic.cache.codec.IFileCodec
44
import com.runetopic.cache.store.Constants.BZIP_HEADER
55
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream
66
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream
@@ -15,7 +15,7 @@ import java.util.*
1515
* @email <[email protected]>
1616
*/
1717
internal class BZip2Codec: IFileCodec {
18-
override fun compress(data: ByteArray, length: Int, keys: Array<Int>): ByteArray {
18+
override fun compress(data: ByteArray, length: Int, keys: IntArray): ByteArray {
1919
val stream: InputStream = ByteArrayInputStream(data)
2020
val bout = ByteArrayOutputStream()
2121
BZip2CompressorOutputStream(bout, 1).use { os -> IOUtils.copy(stream, os) }
@@ -30,7 +30,7 @@ internal class BZip2Codec: IFileCodec {
3030
return Arrays.copyOfRange(buffer, BZIP_HEADER.size, buffer.size)
3131
}
3232

33-
override fun decompress(data: ByteArray, length: Int, keys: Array<Int>): ByteArray {
33+
override fun decompress(data: ByteArray, length: Int, keys: IntArray): ByteArray {
3434
val buffer = ByteArray(length + BZIP_HEADER.size)
3535

3636
System.arraycopy(BZIP_HEADER, 0, buffer,0, BZIP_HEADER.size)

cache/src/main/kotlin/com/runetopic/cache/compression/impl/GZipCodec.kt renamed to cache/src/main/kotlin/com/runetopic/cache/codec/impl/GZipCodec.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package com.runetopic.cache.compression.impl
1+
package com.runetopic.cache.codec.impl
22

3-
import com.runetopic.cache.compression.IFileCodec
3+
import com.runetopic.cache.codec.IFileCodec
44
import org.apache.commons.compress.utils.IOUtils
55
import java.io.ByteArrayInputStream
66
import java.io.ByteArrayOutputStream
@@ -12,14 +12,14 @@ import java.util.zip.GZIPOutputStream
1212
* @email <[email protected]>
1313
*/
1414
internal class GZipCodec: IFileCodec {
15-
override fun compress(data: ByteArray, length: Int, keys: Array<Int>): ByteArray {
15+
override fun compress(data: ByteArray, length: Int, keys: IntArray): ByteArray {
1616
val inputStream = ByteArrayInputStream(data)
1717
val outputStream = ByteArrayOutputStream()
1818
GZIPOutputStream(outputStream).use { os -> IOUtils.copy(inputStream, os) }
1919
return outputStream.toByteArray()
2020
}
2121

22-
override fun decompress(data: ByteArray, length: Int, keys: Array<Int>): ByteArray {
22+
override fun decompress(data: ByteArray, length: Int, keys: IntArray): ByteArray {
2323
val outputStream = ByteArrayOutputStream()
2424
GZIPInputStream(ByteArrayInputStream(data, 0, length)).use {
2525
IOUtils.copy(it, outputStream)
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
package com.runetopic.cache.compression.impl
1+
package com.runetopic.cache.codec.impl
22

3-
import com.runetopic.cache.compression.IFileCodec
3+
import com.runetopic.cache.codec.IFileCodec
44

55
/**
66
* @author Tyler Telis
77
* @email <[email protected]>
88
*/
99
internal class NoFileCodec: IFileCodec {
10-
override fun compress(data: ByteArray, length: Int, keys: Array<Int>): ByteArray {
10+
override fun compress(data: ByteArray, length: Int, keys: IntArray): ByteArray {
1111
throw NotImplementedError("No codec provided.")
1212
}
1313

14-
override fun decompress(data: ByteArray, length: Int, keys: Array<Int>): ByteArray {
14+
override fun decompress(data: ByteArray, length: Int, keys: IntArray): ByteArray {
1515
throw NotImplementedError("No codec provided.")
1616
}
1717
}

0 commit comments

Comments
 (0)