Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,27 @@ A cache library written in Kotlin.
- Java Version 16

# Supported
- RS2 (414-742)
- RS2 (414-772)
- RS3 (773-~788)
- OSRS (1-current)

# Features
- Thread-safe
- Cache Loading
- Definitions/Providers Loading
- Cache Reading
- Definitions/Providers Loading
- Fast (Limited by I/O)

# TODO
- Cache Writing
- Flat file system for unpacking the cache files into a raw format that can be git versioned.
- Support for RS2 caches revision 743+.
- ~317 cache format support.
- RS3 caches.
- Testing
- Flat File System
- Ondemand Data Caching
- 317 and older support
- Tests

# Implementation
Just use cache if you do not require any of the revision specific loaders.
```
cache = { module = "com.runetopic.cache:cache", version.ref "1.4.11-SNAPSHOT" }
loader = { module = "com.runetopic.cache:loader", version.ref "647.6.1-SNAPSHOT" }
cache = { module = "com.runetopic.cache:cache", version.ref "1.4.15-SNAPSHOT" }
loader = { module = "com.runetopic.cache:loader", version.ref "647.6.3-SNAPSHOT" }
```

```
Expand All @@ -45,7 +44,7 @@ Index -> Group -> File

### Creating a new JS5 store
```
val store = Js5Store(Path.of("/path/"))
val store = Js5Store(path = Path.of("/path/"), parallel = true)
```

### Getting an index
Expand Down
4 changes: 2 additions & 2 deletions cache/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
signing
}

version = "1.4.11-SNAPSHOT"
version = "1.4.15-SNAPSHOT"

java {
withJavadocJar()
Expand Down Expand Up @@ -77,5 +77,5 @@ dependencies {
implementation("com.michael-bull.kotlin-inline-logger:kotlin-inline-logger:1.0.3")
implementation("org.slf4j:slf4j-simple:1.7.32")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.13.+")
implementation("com.runetopic.cryptography:cryptography:1.0.4-SNAPSHOT")
implementation("com.runetopic.cryptography:cryptography:1.0.6-SNAPSHOT")
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ package com.runetopic.cache.exception
* @author Tyler Telis
* @email <[email protected]>
*/
class CompressionException(override val message: String): RuntimeException(message)
internal class CompressionException(override val message: String): RuntimeException(message)
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ package com.runetopic.cache.exception
* @author Tyler Telis
* @email <[email protected]>
*/
class DatFileException(override val message: String): RuntimeException(message)
internal class DatFileException(override val message: String): RuntimeException(message)
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ package com.runetopic.cache.exception
* @author Tyler Telis
* @email <[email protected]>
*/
class EndOfDatFileException(override val message: String): RuntimeException(message)
internal class EndOfDatFileException(override val message: String): RuntimeException(message)
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ package com.runetopic.cache.exception
* @author Tyler Telis
* @email <[email protected]>
*/
class FileDataException(override val message: String): RuntimeException(message)
internal class FileDataException(override val message: String): RuntimeException(message)
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ package com.runetopic.cache.exception
* @author Tyler Telis
* @email <[email protected]>
*/
class FileNotFoundException(override val message: String): RuntimeException(message)
internal class FileNotFoundException(override val message: String): RuntimeException(message)
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ package com.runetopic.cache.exception
* @author Tyler Telis
* @email <[email protected]>
*/
class IdxFileException(override val message: String): RuntimeException(message)
internal class IdxFileException(override val message: String): RuntimeException(message)
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ package com.runetopic.cache.exception
* @author Tyler Telis
* @email <[email protected]>
*/
class ProtocolException(override val message: String): RuntimeException(message)
internal class ProtocolException(override val message: String): RuntimeException(message)
71 changes: 7 additions & 64 deletions cache/src/main/kotlin/com/runetopic/cache/extension/ByteBuffer.kt
Original file line number Diff line number Diff line change
@@ -1,70 +1,13 @@
package com.runetopic.cache.extension

import com.runetopic.cache.store.Constants.cp1252Identifiers
import com.runetopic.cryptography.toWhirlpool
import java.nio.ByteBuffer
import java.nio.charset.Charset

fun ByteBuffer.readCp1252Char(): Char {
var unsigned = get().toInt() and 0xff
require(unsigned != 0) { "Non cp1252 character 0x" + unsigned.toString(16) + " provided" }
if (unsigned in 128..159) {
var value: Int = cp1252Identifiers[unsigned - 128].code
if (value == 0) value = 63
unsigned = value
}
return unsigned.toChar()
}
internal fun ByteBuffer.readUnsignedByte(): Int = get().toInt() and 0xFF
internal fun ByteBuffer.readUnsignedShort(): Int = short.toInt() and 0xFFFF
internal fun ByteBuffer.readUnsignedIntShortSmart(): Int = if (get(position()).toInt() < 0) int and Int.MAX_VALUE else readUnsignedShort()

fun ByteBuffer.readUnsignedSmart(): Int {
val peek = get(position()).toInt() and 0xFF
return if (peek < 128) readUnsignedByte() else (readUnsignedShort()) - 0x8000
}

fun ByteBuffer.readUnsignedSmartShort(): Int {
return if (get(position()).toInt() < 0) int and Int.MAX_VALUE else readUnsignedShort()
}

fun ByteBuffer.readUnsignedByte(): Int = get().toInt() and 0xFF
fun ByteBuffer.readUnsignedShort(): Int = short.toInt() and 0xFFFF
fun ByteBuffer.readMedium(): Int = (get().toInt() and 0xFF) shl 16 or (get().toInt() and 0xFF shl 8) or (get().toInt() and 0xFF)
fun ByteBuffer.skip(amount: Int): ByteBuffer = position(position() + amount)

fun ByteBuffer.readUnsignedIntSmartShortCompat(): Int {
var value = 0
var i = readUnsignedSmart()
while (i == 32767) {
i = readUnsignedSmart()
value += 32767
}
value += i
return value
}

fun ByteBuffer.whirlpool(): ByteArray {
val position = position()
val data = ByteArray(limit())
get(data)
position(position)
return data.toWhirlpool()
}

fun ByteBuffer.readString(): String {
val mark = position()
var length = 0
while (get().toInt() != 0) {
length++
}
if (length == 0) return ""
val byteArray = ByteArray(length)
position(mark)
get(byteArray)
position(position() + 1)
return String(byteArray, Charset.defaultCharset())
}

fun ByteBuffer.remainingBytes(): ByteArray {
val b = ByteArray(remaining())
get(b)
return b
internal fun ByteBuffer.remainingBytes(): ByteArray {
val bytes = ByteArray(remaining())
get(bytes)
return bytes
}
8 changes: 0 additions & 8 deletions cache/src/main/kotlin/com/runetopic/cache/extension/Int.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.runetopic.cache.extension

fun String.nameHash(): Int {
internal fun String.nameHash(): Int {
var hash = 0
this.forEach { element -> hash = element.toInt() + ((hash shl 5) - hash) }
return hash
Expand Down
Loading